From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 4B0C71B7F4 for ; Tue, 17 Feb 2026 08:42:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771317773; cv=none; b=Lkl544Rh9n7k+a7ysPo3FrPXmbHwpLBaot1j1nQldnQaXWSi4FZu9U8fWjSndfeI6705ydnmo+kgD+4Z27Au317q41yx/AavkvIH0iBGvGONpA05kEmHpZalrhTGtDtyx0hlUS42CMZOM+CY0/MK8zj4B8MjtCD3wuRZvemMLiQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771317773; c=relaxed/simple; bh=K2FQH7PpMIibguGrGrhzt8FddGrBV6kQkMRnHRoduiQ=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:Content-Type; b=EVxOVh7z/d3G8D9G0NVLKEuSTjzGqLw66XCZ5cjrM8A2PBKL9E7vcKQlWEe7UxW4D/mgqEfls7e5hp7lFOPbd2vKCgudtvkQnqSyq4n03f/dDsREWXnMdwum+eo+60Br69/oXAtqG+iX7mBRjnK/cIpk3tpfgdGOUADtZeULTv8= 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=FmPrPIef; arc=none smtp.client-ip=209.85.167.49 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="FmPrPIef" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-59e699310a8so4178786e87.1 for ; Tue, 17 Feb 2026 00:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771317770; x=1771922570; 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=Fpq2RAxNFCz9UvUxD0Qdy48glGRDkBg6Q4EVfiWiPYg=; b=FmPrPIef+xL52xBgswt0GbtOACk39NoDnA2M8XT5aQp+yydacCOUqEeSICQNFU4Has 96PUUF92GrV2T+OIkAVP0TjVxLLVbfwM9ZBBPT79NRsHe9rVoPYWDVqLJcycRnlfuRuq yea3DDvBMuqcZeZuYL9OOWec7nUZxFj+nAiAXQshPkaLgGkGzsRLs4WOLtF90PS5spTf aJgcpxBaGrUKfW7nm3pfDOFSHn7kOwlKokqfaVocWn6YGFoxUZ82MCMpruVKbbhNhM3F 99At2fYOR9OVAP837+YydiSYhT8AtT/W3yCApeuQ5D40EkZFUmlNzxvlAfrKhGq4MbYr d5UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771317770; x=1771922570; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Fpq2RAxNFCz9UvUxD0Qdy48glGRDkBg6Q4EVfiWiPYg=; b=VvRwpaFFKV28gZatubko39cW+cE0lZ66agJWE6u/6AjejRGmuWNSiMaw8i5k4t03ta IeJnmLLEnKzP3fjwu1z00hpEXGcVcG2AM4SuXAbhB1P/ZmvSy6vcdwVA1X1eYtyUQxUF o9Buz3yYotmdmw6lZsrkxICbzq2ap79gGe5SWEucwLhVk4CLNN0OFiHe3LPeL6przg6i JgBcYkuwjXCuTHS12h0KylmufM7KGTgd8KKITFQTxjR6mpwnQJbLa1gIBkHJawAetowp vq3hhb8fz5E2lJGWF6K8tYouoZmzOh7rsh6GgAbOP5XUyryJ7Xd/BzXbvzsxgr3PjHO/ oDcQ== X-Forwarded-Encrypted: i=1; AJvYcCUx9QtWiRhq1+rainet+N1w19s0TyJYwl1J3sNk4ISdiFLgoEUcnd43fL72KOS0BTBXLq4wT026U9kvoB8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywe7PbokvhRg5YtAU4qccCY7xM5phtFh4xZ/8bO5p7QRtUufbxe 2fA9bJ1E5fkVaCxHHI5MDSaJgdXFRTV2JKqqM525a0aO+gwamqWWpss1 X-Gm-Gg: AZuq6aLstdQ6Cze+eC7JHAHnzeKys2AzgZkA32+IdfYOblU9Cl3GRJYEYyeK/vvncod 1W3JwgSTadQy3PWYGYROewylrbeEzJUTzhMilLzLByNvP9OyMqtGeKKTj6rmtW9kIdRdIamK8Zz 1Sri3b0Nk5lvHCwpYFTT5WYYMSRP4HUknt9QptOfkBMSBQWpDLIXBrNTHxm6Co0yrDj57f9Dh8e yuzniLoW6OCoOCNOIFHQRxIPNTf3U85A2FAaavx9wvygv2qdwzs5kjmKdpL8csGJaCxOI3OKjRW x6qE4Uk/BxbehKkKzoivW24qDj9TbVWP5AC/QUgIoDBTocXvx15TCB5KYXYAl1tdSTQcjCFDnFv CkOCmy7T+Gy4KYzHl2V/czGRo3KK2DoeLVIVs0axlzaw1f+XVvwnSN2X6hhMMDkrH+6I7xhCuHZ J/FgMvKmAXm4Ql5j3ongBDOBnVlxYrj9kOehFyBpulBRkE X-Received: by 2002:a05:6512:239d:b0:59e:4f90:44e1 with SMTP id 2adb3069b0e04-59f6cfcbf5bmr3881569e87.10.1771317770226; Tue, 17 Feb 2026 00:42:50 -0800 (PST) Received: from [10.128.170.182] ([77.234.210.12]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-59e5f5a5096sm3723433e87.47.2026.02.17.00.42.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Feb 2026 00:42:49 -0800 (PST) Message-ID: Date: Tue, 17 Feb 2026 11:42:49 +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: File size is not persisted after opening the file with O_TRUNC flag and creating hard link 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: 8bit Detailed description ==================== Hello, there seems to be an issue with btrfs crash behavior: 1. Create an empty file in a directory. 2. Fill file with data (e.g. truncate) and sync the file. 3. Open file with O_TRUNC flag (should set size to 0) and sync the file. 4. Create a new hard link to the file in the same directory. 5. Sync the directory. After system crash the file will have the old size (>0) even though the file was synced after truncating (O_TRUNC). System info =========== Linux version 6.19.2 How to reproduce ================ ``` #include #include #include #include #include #include #include int main() {   int status;   int file_fd;   int dir_fd;   status = creat("file1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);   printf("CREAT: %d\n", status);   status = truncate("file1", 1000);   printf("TRUNCATE: %d\n", status);   sync();   status = open("file1", O_RDWR | O_TRUNC);   printf("OPEN: %d\n", status);   file_fd = status;   status = fsync(file_fd);   printf("FSYNC: %d\n", status);   status = open(".", O_RDONLY | O_DIRECTORY);   printf("OPEN: %d\n", status);   dir_fd = status;   status = link("file1", "file2");   printf("LINK: %d\n", status);   status = fsync(dir_fd);   printf("FSYNC: %d\n", status); } // file size is 1000 instead of 0 ``` 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 file size is 1000 instead of 0.