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 D21122E8B74 for ; Wed, 3 Dec 2025 11:26:26 +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=1764761188; cv=none; b=btmUH3gxp3jo8P1rFuv5Y9BMtpp1pBC2gPP3c2Fy+6yDo81YxEBaTMfCTWlbOgE9ZNNsssp8ick8salYVHiOW3xKS6FiyfxVyyxUsKU717VaZ2STlSQkTgBVz1dD6NeAA52Z6LzVxRAaG15jAvelPcGVN5W+4X4XN88XuTk+610= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764761188; c=relaxed/simple; bh=vgRlZloTI+VMwHD3FCjNwwDWn3CtZXJord3wWo74wds=; h=Message-ID:Date:MIME-Version:From:To:Cc:Subject:Content-Type; b=VEc/Vc8+TxDaR3WDSmVQadd/249wlvvCbaXrSDEbQRyn+/HSjdn02cjRTJ9LAKQxUNFSFGmLHUnNgpS8F4SP4IG6EtXMvp6Kq45MGhhYjbNSvc74RSR0NKp76tHZzKxej24BdyoHEELVPVY2DBK+bwk1sRhFj0uB16SBAAuEODw= 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=Yf3/q3J6; 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="Yf3/q3J6" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-59584301f0cso5740845e87.0 for ; Wed, 03 Dec 2025 03:26:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764761185; x=1765365985; darn=vger.kernel.org; h=content-transfer-encoding:subject:cc:to:from:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=FhIEIr30EK2YFUF+AiavoLZElSeoj3prKR2BxIxzB4k=; b=Yf3/q3J673+6W9cnOrRBmWuOXm0Jsm7Mx0Vg9vu6QQZDAwoBEyWeG06FOK6aw9ujHD KE6INlTqKMGErVM80JjAhBlNGFatyAYhLlsntoLKxNPA25JNjaAUvoNEVWTV2kRcx9Xl +0mLPCVx+xGU+6kjJT7Hn5zWNKFMjaHpJ2udv1x/0DBYjccEf182xpMjQnLYjjN9iDFO j5Mcy8SVzXqYtNovlV7XwUeySuW5E/8wMCtbAOJ5oVEERdPH0Gy2nHM/Uiz0wV40T12D 6U1E/TGoUVHpjsKpXL4GvIgHIc6FgMzLbqjkPen0yswXT5eTH7ZuTfL12ooDRgpDS8dD eH3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764761185; x=1765365985; h=content-transfer-encoding:subject:cc:to:from:content-language :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=FhIEIr30EK2YFUF+AiavoLZElSeoj3prKR2BxIxzB4k=; b=Y7Cas5qBecUpN0614x9KX9YtiNonscc+T91jDlP1Q5awtS2yoXCh/AVlJcCmQeahfu tk1Igecmdy85PsAOw5GgblAWhL2GausmC0ZAi+wI9uCNlH27haD1vY0KoSTwuSA6+7uM sMfeqFc7ZHzQndpFf/1nFwRcC2Nc7LnOlqcvl2JdkYFcg87lCROyGEFUOl03ETlToyon sDiMpHiX8AxmN2aQnBBQPz8cB/RwiaVx5iJcTUUlKJNauXL05ebjACpsnn380dQd35WR 8kgqo9PNaKApHhw7reOcPmjxQJvc1gGuerZ5qqo3/GKSvwWn80zkbdYN2ZmjBA8rmL+l gibQ== X-Forwarded-Encrypted: i=1; AJvYcCX4dxGaFYFGedKF3f6kWmhHajWGa7FGh02dZA5eA5yAH9xKPIZbLgdBbnuGF5DjMdauRVbT32t/NA55Nxs=@vger.kernel.org X-Gm-Message-State: AOJu0YzUFe7uUFXO4wicktcZq0IBGPDCoBoHjDF1E/bvsUb6PaLJJDpZ g+pH+PVLz4vn3Cy73FNUM8IcoU7vue5Z7s0CqajtYIuiT8ZuYScZ1wgx X-Gm-Gg: ASbGncs5nECv8w8aOpzjD+5fSFSkGLVpn/p4wrujv8e+5YuxjsVQiyqhW4+D4JmJG3y pgsIZyEEWM4HGBw7jeX5oXzUicit0MbWtS9TD+M5qfzYDkg1G0jBjQbRwumlAEmTnxr5kNxFd5D YySMmKQW/2WNtBSyEMjciC5HhdJf9/IJlTEAXMK5l8NTyKXr7YVj9Ocdp/bI3kizphrB4yinW34 rM6TEC9S6KNFr8Vh+xDb7dwwRzw65EVhrv1tWZAsdJ/ncKvcYFjZZuoBlqh8A6sVCJp2xbCToW3 wjEqkq1lTVchhaBBbzcPKaVy9oJchQct3X+Lm0sSHHmEMP6ZMcsDVj0rSmJ2E0ejpIks0H3FV+I srlvoHY0e04GA/KtToTv7Sk799ykEg4+BVoS6QgD9CqQB/7SxxoB+zhghCYndr0NCTI02WoHzbC KGKgWhvNzfaY9Y8a9p7bFUVKLSYwBcvdNM X-Google-Smtp-Source: AGHT+IHtFrMK/G54Aab8Rllz+zFVNRtz8oZcJCrDALjIMMr6Av1YFpJWF1SGnPVmhbWJUe7wR9EXLA== X-Received: by 2002:a05:6512:1088:b0:594:347e:e679 with SMTP id 2adb3069b0e04-597d3ff2fb6mr738197e87.43.1764761184567; Wed, 03 Dec 2025 03:26:24 -0800 (PST) Received: from [10.128.170.160] ([77.234.210.12]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-596bf8a7c7asm5615807e87.15.2025.12.03.03.26.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Dec 2025 03:26:23 -0800 (PST) Message-ID: <84c4e713-85d6-42b9-8dcf-0722ed26cb05@gmail.com> Date: Wed, 3 Dec 2025 14:26:22 +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 Content-Language: en-US From: Vyacheslav Kovalevsky To: clm@fb.com, dsterba@suse.com Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Directory is not persisted after creating 100s of files inside, writing to another file and renaming it if system crashes. Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Directory entry is not persisted after creating 100s (hundreds) of files inside, writing to another file (with `O_SYNC` flag) and renaming it if system crashes. Detailed description ==================== Hello, we have found another issue with btrfs crash behavior. In short: 1. Create and sync an empty file in root directory. 2. Make new directory in root directory. 3. Open the file with `O_SYNC` flag and write some data (of specific size). 4. Fill directory with specific number of empty files. 5. Rename the previously written file. 6. Sync root directory. After system crash directory will be missing, although it was synced in the last step. System info =========== Linux version 6.18, also tested on 6.14.11. How to reproduce ================ ``` #include #include #include #include #include #include #include #define BUFFER_LEN 1024 // should be at least ~ 528 #define FILE_N 256 // should be at least ~ 128 int main() { int status; int file_fd; int root_fd; int buffer[BUFFER_LEN + 1] = {}; for (int i = 0; i < BUFFER_LEN; ++i) { buffer[i] = i; } status = creat("file1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); printf("CREAT: %d\n", status); close(status); // persist `file1` sync(); status = mkdir("dir", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); printf("MKDIR: %d\n", status); // `O_SYNC` is important status = open("file1", O_WRONLY | O_SYNC); printf("OPEN: %d\n", status); file_fd = status; status = write(file_fd, buffer, BUFFER_LEN); printf("WRITE: %d\n", status); char path[100]; // fill directory with a lot of empty files for (int i = 0; i < FILE_N; ++i) { sprintf(path, "dir/%d", i); status = creat(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); close(status); } status = rename("file1", "file2"); printf("RENAME: %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); } // after the crash `dir` is missing ``` 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.