From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EADA83093D3 for ; Fri, 24 Oct 2025 15:19:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761319151; cv=none; b=T5wQseDkRBVTNgj/WbXXgSz4siA5yyAi6EoDK3+0VwKAgAfjaAd4k35/doPdcOsK4RWddeWh9YfyQLV0+t6YTW3hCQzFR66TcsAILTWuu6cANO/Bt9/PvWjz8dUnBQcDpitXysuI86SBlPGHf9gQGj2D+T9o8keIchO1T/KQdbs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761319151; c=relaxed/simple; bh=A1nZgSHLk3Ea+o8JUU07BQK973AUy09cBcqjoCtV9uI=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:Content-Type; b=c9vYsqLMYRGXaFzeEwVuGZWMNY4G7cwkahT62+kxsNxHHgwuq8KurA0yQVtquCmvIV4la25RXyEDnXKXtNr4lMSnWSvBkyxDxCrf5aTPmrsRh4l3WFMZDJpk3qosHm+ERjsZv5FQ7eVtGeAj7IDEqWvCBIG2Qr1icopgVBxKUzA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ioj7k02r; arc=none smtp.client-ip=209.85.167.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ioj7k02r" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-57e8e67aa3eso4957594e87.1 for ; Fri, 24 Oct 2025 08:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761319147; x=1761923947; darn=vger.kernel.org; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=MIwyZW9sidCDypOWd4vP2sZ/37yenpkNQ950ZzRaSzg=; b=Ioj7k02rDixVhB5IwqfivZLAaN7Qe4LQkpURMYF+1N/3z6nnUSY06Rr0Qb7rsU/x35 B/JHPFXavilwhpTg2xbkfefRbopEugf01QF+ds6hW9wkhUy0PHhi7+3JFJklMRnPTHP9 xnglpKLyXovdx6i2qC9IIgFr+E66G0IsMOrVQnvf1quSFXTKdaRJffTBCOZbWiz7xK32 xlpkjLZcCg/K8EJ2qq8ZoYv9NXDsJ6eVjnpabnMt3TG2tSihfk2CA34/+4LlaeycZADQ dolIANIche/HvmA9sXzlGLSeV6MVyxP1vpBp4zpRhkYI5zC5OAEp0CgTEdzVDWM0Dm65 1fAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761319147; x=1761923947; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=MIwyZW9sidCDypOWd4vP2sZ/37yenpkNQ950ZzRaSzg=; b=AttDka8t41u+jslvoO76g4Ld3r1ZoMqxE5tNIQ30oLlmF97IcPQbcZy6PQBqXxhsQp 0d9/GnvtYHWgN1fmXmTEx6e7q+CHeVIy6mSpFOilBHpNNkxZAlI3PXYAZkjW8uHlyhz5 e0HARLw9GcoaC/XzLhfpMaBu+5sbQURllwuNYFlu3CR+L/kq7INbYuioPOpoEc0T+n3x c0JP4q45J0MMCN2YrHmUypm8vWlehiAbZachjsqYVDEEaVK6v1Ji2+JyOj5HHxtw3xxl UC+7Avm5cvs98nw7lqtrLvgm80VUTVPOD0j+H8IGx5UQR6KACRdb2BCd7YMUesXsKisb g96g== X-Forwarded-Encrypted: i=1; AJvYcCU8qy4mW3MwwzLEwjdnpYzuL8YyD3hSvDsLoi/FxgIDrstR+yVP8SKRzmYCvNWVyQNSp73YkMjN3PGBTuw=@vger.kernel.org X-Gm-Message-State: AOJu0YzoAisCcEoPYQXI93falEmky6/W1WrAQntcHvQO/6FVD+iJxnny IauXys+hkW7wu98iNew0lNyoI0lfC6qEtNoGIJq2y3dzhJhfEZoQ9X7qxvApj6P2 X-Gm-Gg: ASbGncsbe4rjbx4RGU9d3UuuDbfZN4ltUuVTTZzqLWU3hHb1NyF7AQH1QTfIMP+D9hz xr5j0fEmbkMDoSfSNS3n9FLZ6gBCoDx/BfDDzyGvFeSyp62MwIlGfPjBKcJkGudZhk2nVaH4cZO TVekeC/QAnKC2takcjcJPTmNrpY6erNH8I3qi8tlAHP9GixcuHfeBzKLV74fTEoWrczjPjN+D8l O6IC3jdRad1LpQwGDztB5tJLIRAk0hrqU8VooP2cJ82prrEImy2fskUzln+8bshtAacHvGqKBtM /9QQYmNjNZZzLOhNhIDkogOv4pPZV1l8fDWKOQdPXt45OH1kdQnzbeYvXgH1/SPOYqltHRP31Dl 15S1K140U6/xkFb71LDFw/hYa0zBErCAmJYBAHu2BLj3W/6GIGdMHCMX2GmOVwP9Z3gmyTnVsd6 YyKJ8dFcJAgHRGisFXWKDF1fjJXYrccwf5 X-Google-Smtp-Source: AGHT+IEMahbi2fLPVnugBt7nBQpOJJXmfytKLyhTafnrSXtfTi0+A8tdG0+Nc8NOHGuU6LWNqGXYIA== X-Received: by 2002:a05:6512:1502:10b0:592:fc5a:b6bb with SMTP id 2adb3069b0e04-592fc5ab708mr774549e87.6.1761319146729; Fri, 24 Oct 2025 08:19:06 -0700 (PDT) Received: from [10.128.170.160] ([77.234.210.12]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-592f4d1f3bdsm1731154e87.81.2025.10.24.08.19.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Oct 2025 08:19:06 -0700 (PDT) Message-ID: <03c5d7ec-5b3d-49d1-95bc-8970a7f82d87@gmail.com> Date: Fri, 24 Oct 2025 18:19:05 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Vyacheslav Kovalevsky Subject: Directory is not persisted after writing to the file within directory if system crashes To: clm@fb.com, dsterba@suse.com Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Under some circumstances, directory entry is not persisted after writing to the file inside the directory that was opened with `O_SYNC` flag if system crashes. Detailed description ==================== Hello, we have found another issue with btrfs crash behavior. In short, empty file is created and synced. Then, a new directory is created, old file is opened with `O_SYNC` flag and some data is written. After this, a new hard link is created inside the directory and the root is `fsync`ed (directory should persist). However, after a crash, the directory entry is missing even though data written to the old file was persisted. System info =========== Linux version 6.18.0-rc2, also tested on 6.14.11. How to reproduce ================ ``` #include #include #include #include #include #include #include int main() { int status; int file_fd; int root_fd; status = creat("file1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); printf("CREAT: %d\n", status); // persist `file1` sync(); status = mkdir("dir", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); printf("MKDIR: %d\n", status); status = open("file1", O_WRONLY | O_SYNC); printf("OPEN: %d\n", status); file_fd = status; status = write(file_fd, "Test data!", 10); printf("WRITE: %d\n", status); status = link("file1", "dir/file2"); printf("LINK: %d\n", status); status = open(".", O_RDONLY | O_DIRECTORY); printf("OPEN: %d\n", status); root_fd = status; // persist `dir` status = fsync(root_fd); printf("FSYNC: %d\n", status); } ``` Steps: 1. Create and mount new btrfs file system in default configuration. 2. Change directory to root of the file system and run the compiled test. 3. Cause hard system crash (e.g. QEMU `system_reset` command). 4. Remount file system after crash. 5. Observe that `dir` directory is missing. Notes: - ext4 does persist `dir` and `dir/file2` even though it was not synced. - xfs does persist `dir` but does not persist `dir/file2`. P.S. Want to apologize for formatting in previous report, first time using Thunderbird and plain text.