Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2338439imm; Mon, 28 May 2018 06:19:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo6iOi87oCVIZU/C7AfVo+iwPensrqzhKMNGz109CAoRg5GLUgpeJ8emg/RPl9ubQfuI5eJ X-Received: by 2002:a62:5b02:: with SMTP id p2-v6mr13383257pfb.96.1527513581335; Mon, 28 May 2018 06:19:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527513581; cv=none; d=google.com; s=arc-20160816; b=f1OkMivvV+b+/dPCGekk4P8gsLtO+kCncequKyAGdWguOrVXHUFM2jkLjknAhi+7K7 H1go7/+SfmWyZIPN1P/e5xAKDL+b+9f1D7Y+4zdYm/aOsrgkJewccx0wFcoqpGqPMWU1 EIKAwjWd8TuGsn3mzZX/zzajkmB+gHJ7qYc9lbYjFKMU0b7jqnezASQJn4zedU2GWqlm oeZPdL3CnwFYuK3XBYld0HwmPu8bJd/T8FItXISyQLtxG3h4RgwcSsE43yrk+NtU4PUw czEGWY4l2v68V+0VnevyAxHqqs4u8/Lr+bXELlJl5zMwdcA0ahKJrC8c8r5Heh3UwFNK Fr8A== 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=y6cdfs/L/eUuxaTSjrVST+dXXL4jM5/n6RHqEK8Z4sU=; b=iCV94fQ1xura2WxDMknROPiIeSBRlqEv+YUOJ7/I+4Ytk9Lb8dLHP08jSSZqFZ339M gBk5j+V2A8ed/kiZ3GCxSp5MD9KXP1ojlShsquVdYhO6Et/HwDidUCHdt0blFhf9SaNU K7IAHYWWFtOMQhT6bmQ1ZnKZa60IIqzUUW4EPmMKUBTC/67BSyOMCjuYWzYcQC49+RhZ mWQYIVaiKYAtA3AovKh1Pug4OFZmmxqFZ0nQ5/dB6ToICx5R+CeH5XG8cGVNSYX5kTiC yhLUc69ZbsrPN+T8k/0xR/04+XsqGom6M/eeL3+zA2PDhcNUgcwV6xmKRmUqtJa7M8rh lmAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pQH6tdnA; 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 e15-v6si23795563pgr.400.2018.05.28.06.19.26; Mon, 28 May 2018 06:19: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=pQH6tdnA; 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 S1165305AbeE1NSs (ORCPT + 99 others); Mon, 28 May 2018 09:18:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:39456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163574AbeE1Ktu (ORCPT ); Mon, 28 May 2018 06:49:50 -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 B9C20204EE; Mon, 28 May 2018 10:49:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504590; bh=ETVM2PWRk/FUSp5WdZhgY4pNWxk2+/qSewrbqXGYaao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pQH6tdnAc/Oav9cCE85b0mcGycjhfr/JQObTJNC3/BYUk//ZADTwaNhF4YktOeRsn dJzU5ZB9D3e/szfmSqEMrnS8+3GbiHyxR1/lItLeeZdyKn31fcHxO1NIchHx8x4Q3i BG4ZeXylQnalvnFGaD4VXj3R2fUTQ64hBHhSourM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba , Sasha Levin Subject: [PATCH 4.14 193/496] Btrfs: fix log replay failure after linking special file and fsync Date: Mon, 28 May 2018 11:59:38 +0200 Message-Id: <20180528100328.068476411@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana [ Upstream commit 9a6509c4daa91400b52a5fd541a5521c649a8fea ] If in the same transaction we rename a special file (fifo, character/block device or symbolic link), create a hard link for it having its old name then sync the log, we will end up with a log that can not be replayed and at when attempting to replay it, an EEXIST error is returned and mounting the filesystem fails. Example scenario: $ mkfs.btrfs -f /dev/sdc $ mount /dev/sdc /mnt $ mkdir /mnt/testdir $ mkfifo /mnt/testdir/foo # Make sure everything done so far is durably persisted. $ sync # Create some unrelated file and fsync it, this is just to create a log # tree. The file must be in the same directory as our special file. $ touch /mnt/testdir/f1 $ xfs_io -c "fsync" /mnt/testdir/f1 # Rename our special file and then create a hard link with its old name. $ mv /mnt/testdir/foo /mnt/testdir/bar $ ln /mnt/testdir/bar /mnt/testdir/foo # Create some other unrelated file and fsync it, this is just to persist # the log tree which was modified by the previous rename and link # operations. Alternatively we could have modified file f1 and fsync it. $ touch /mnt/f2 $ xfs_io -c "fsync" /mnt/f2 $ mount /dev/sdc /mnt mount: mount /dev/sdc on /mnt failed: File exists This happens because when both the log tree and the subvolume's tree have an entry in the directory "testdir" with the same name, that is, there is one key (258 INODE_REF 257) in the subvolume tree and another one in the log tree (where 258 is the inode number of our special file and 257 is the inode for directory "testdir"). Only the data of those two keys differs, in the subvolume tree the index field for inode reference has a value of 3 while the log tree it has a value of 5. Because the same key exists in both trees, but have different index, the log replay fails with an -EEXIST error when attempting to replay the inode reference from the log tree. Fix this by setting the last_unlink_trans field of the inode (our special file) to the current transaction id when a hard link is created, as this forces logging the parent directory inode, solving the conflict at log replay time. A new generic test case for fstests was also submitted. Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -5888,7 +5888,7 @@ int btrfs_log_new_name(struct btrfs_tran * this will force the logging code to walk the dentry chain * up for the file */ - if (S_ISREG(inode->vfs_inode.i_mode)) + if (!S_ISDIR(inode->vfs_inode.i_mode)) inode->last_unlink_trans = trans->transid; /*