Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp799748imm; Mon, 21 May 2018 14:42:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpUMOXIhkUuj0Nw/yg+wcBtymEN60NeO1TD2KnmJIJcRft6vYY8jG6QABcEZ8mRBRAIV14s X-Received: by 2002:a62:ca98:: with SMTP id y24-v6mr21380777pfk.187.1526938961165; Mon, 21 May 2018 14:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526938961; cv=none; d=google.com; s=arc-20160816; b=txL0RtFcKBMci41dKQlN8wRSx0bYptduMrmmzkPaYdVueLXK2KvVsfRwGY7DPe+aCw OMUk7N7bwUrf9ZnRq03D+SJr0B939n3trXLEGEWxEpTk+ZQOS6eSJXhs2AQFfPpdLBMw BzNyEa5k6NT5m9p2rMrksHKYF5cIrfLe5udD8cayHwZhYtzTQU+M/dbARyc5izAVEzD0 V5FE9UKxQx2Se0xpTUvjyQzjICVUq+LYMaKx9fR78NMQdzxVqB2soMOyc8oMKTj6jblA /jO6Mu+jGBw5CgEWx0PdAhQejuUIecu33aq1Iiga1vaxWQc+EhHWjaS9meR/NYfSTB/W W0kQ== 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=lIlLzvu30TYUcyKmZKvcPvtZDzpxrd3hrNpFtNPMnSY=; b=zZzxdSuZFcyCiJ4N1iHJ+Yd2pQTat4G5CHICkK3eawc7Jy88zi3g1ww+JpzDVJZVog J3k/n/FuQjcVIi6EfnkUTuHMuJs0MAeZ2nWqIt7yLl/M6Mc4YOT8ASr/ahhMr6Tv7XcZ bMVIqHPqA3trfQyHVCasU2JHkNi2DkZntuzLqWgWO2vyjKWwxZx9Brv7N69USI5caon2 UuMrhO5I1b1jwTqL1RViG77qde32yOWa5FKi9rBbJshHaJJz15IUgjNGeGz4RTHuCTiX QfMjbKQ97VJYjnub8hqpg4JEf2w5r+T9Mku7lQs6S7jKHNODoP4zhxAIP+bQWAtVa+Ss v6rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FltxVvOe; 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 2-v6si15129788pfk.287.2018.05.21.14.42.26; Mon, 21 May 2018 14:42:41 -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=FltxVvOe; 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 S932297AbeEUVYf (ORCPT + 99 others); Mon, 21 May 2018 17:24:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:39394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932255AbeEUVYa (ORCPT ); Mon, 21 May 2018 17:24:30 -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 22E5520872; Mon, 21 May 2018 21:24:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526937869; bh=fEX5DlkEfDbdvIM4LLwWSjeHWvS7FvB8z/MiX2LJP5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FltxVvOepEvkjx5ddA/5S5fpsa5vAkFqQ1dBNo5dBWNeRd56uVAUlVuUpKcXYTGFy 8VH9Wlb7wr3hvrn8spiin/BS1aj1imj9po64QFilmhmiSKDNyNSg6tfpDN5CdArmWK 2s/cT0c+02C7AtlfI8obYYMLuhCRU8I3CIQqD/Ks= 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.16 055/110] Btrfs: fix xattr loss after power failure Date: Mon, 21 May 2018 23:11:52 +0200 Message-Id: <20180521210510.398647772@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521210503.823249477@linuxfoundation.org> References: <20180521210503.823249477@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.16-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 @@ -4749,6 +4749,7 @@ static int btrfs_log_inode(struct btrfs_ struct extent_map_tree *em_tree = &inode->extent_tree; u64 logged_isize = 0; bool need_log_inode_item = true; + bool xattrs_logged = false; path = btrfs_alloc_path(); if (!path) @@ -5050,6 +5051,7 @@ next_key: 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); @@ -5062,6 +5064,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; }