Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2038714imm; Thu, 24 May 2018 04:57:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrKTYib/r3E6JoWkGDMcnQg7YFdhdsZ36LMUZ6rsMDuOaZQIPpAcpS7gK8fwF161neaPtEu X-Received: by 2002:a17:902:4483:: with SMTP id l3-v6mr7157921pld.282.1527163064129; Thu, 24 May 2018 04:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527163064; cv=none; d=google.com; s=arc-20160816; b=YiBHL43G05+nSDfSNe12BgQgyEc9GwcBybmRFKuba/3cYQ1VyhAF8kJ8AIKlT+YR4L W+OdUbTjvUqU2IHcL+DQODWUnYLfH1wRBmtJWpG6KdR/I19J2R52onYImWGrY1XV87wJ 4E7ZUospScNJ15lG16CcooBQ05LcLbVoqiM1dCKEw14dIqLnK+0uFXwvMiAlaVle3oI0 xhSUDrQX5HrvZIHgaFh9haJ0q2EXa8FOTI5jfdECxrdszABQLSs9tlB7hTfrE5GpRMhK VWukCDIla9y3x4Rmm6zjgORqd8/8VC7MFI6kul892A1cjMoUOb7N5lq+y9ePIuS80XmC mKEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=yphp+Zr1qGMjNi/65X36Nz0UxP1G3zDKQvLoZ32YI0w=; b=YvSiA6XkGj/TCFoEThUCUc7rGdd8mpQP+sjgs9Uw/Z39YHfnwDz1N0iwtdKxKVjzo4 jwH9Jge3j+cXBphe1M5euwms48XAwCfCvxVNtIVNGU7JCl1K347Yl5o3KxBa0/Yqr8Z6 SgXqmLmxzhg7yjmUD2k+ITwfmU1IB4QEhrK9XKCcTFffkS5W9YMih2o0Rm9/ItEYup2R kP88OVVGt+t4581/+OKKvvxE1YubORPOn12bTCz49tjw5IPZd4Q5nCssrOwSr7laCqY0 Zr1lzQAbIKDS9hvxJ7BV4ha2GG96tCYCEsva9CBJfRIPiyGJ5Ylvsocn5d8BvkRSnsKo MU/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aTXACcrx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10-v6si20212758pfn.256.2018.05.24.04.57.29; Thu, 24 May 2018 04:57:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aTXACcrx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966825AbeEXJpn (ORCPT + 99 others); Thu, 24 May 2018 05:45:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:56794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966782AbeEXJph (ORCPT ); Thu, 24 May 2018 05:45:37 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A6CE7208C3; Thu, 24 May 2018 09:45:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155137; bh=GCUt48TjKCL46NfCOutK8curBtG4okRO8ThBqW6bdt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aTXACcrxWd0oNDADhZqqWE8f9hpmitHGpjwpc3k2CH7genXIwuFgqcrOQxkkuF2q6 ijBhCpGQWZoC/XQWyfzKMrECY19sT4e/w4zvTKRRkauA1jcMHEvGMYezbLTP6IWi8L ceNwg9onjm9aDTZNLvCOASFbDxZ6CnsmTC/+xxuo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba Subject: [PATCH 4.4 68/92] Btrfs: fix xattr loss after power failure Date: Thu, 24 May 2018 11:38:45 +0200 Message-Id: <20180524093205.854008094@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana commit 9a8fca62aacc1599fea8e813d01e1955513e4fad upstream. If a file has xattrs, we fsync it, to ensure we clear the flags BTRFS_INODE_NEEDS_FULL_SYNC and BTRFS_INODE_COPY_EVERYTHING from its inode, the current transaction commits and then we fsync it (without either of those bits being set in its inode), we end up not logging all its xattrs. This results in deleting all xattrs when replying the log after a power failure. Trivial reproducer $ mkfs.btrfs -f /dev/sdb $ mount /dev/sdb /mnt $ touch /mnt/foobar $ setfattr -n user.xa -v qwerty /mnt/foobar $ xfs_io -c "fsync" /mnt/foobar $ sync $ xfs_io -c "pwrite -S 0xab 0 64K" /mnt/foobar $ xfs_io -c "fsync" /mnt/foobar $ mount /dev/sdb /mnt $ getfattr --absolute-names --dump /mnt/foobar $ So fix this by making sure all xattrs are logged if we log a file's inode item and neither the flags BTRFS_INODE_NEEDS_FULL_SYNC nor BTRFS_INODE_COPY_EVERYTHING were set in the inode. Fixes: 36283bf777d9 ("Btrfs: fix fsync xattr loss in the fast fsync path") Cc: # 4.2+ Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-log.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4568,6 +4568,7 @@ static int btrfs_log_inode(struct btrfs_ struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; u64 logged_isize = 0; bool need_log_inode_item = true; + bool xattrs_logged = false; path = btrfs_alloc_path(); if (!path) @@ -4808,6 +4809,7 @@ next_slot: err = btrfs_log_all_xattrs(trans, root, inode, path, dst_path); if (err) goto out_unlock; + xattrs_logged = true; if (max_key.type >= BTRFS_EXTENT_DATA_KEY && !fast_search) { btrfs_release_path(path); btrfs_release_path(dst_path); @@ -4820,6 +4822,11 @@ log_extents: btrfs_release_path(dst_path); if (need_log_inode_item) { err = log_inode_item(trans, log, dst_path, inode); + if (!err && !xattrs_logged) { + err = btrfs_log_all_xattrs(trans, root, inode, path, + dst_path); + btrfs_release_path(path); + } if (err) goto out_unlock; }