From unknown Sat Sep 20 07:39:15 2025 X-Loop: help-debbugs@gnu.org Subject: bug#56392: `cp --reflink=always` creates empty file on failure Resent-From: Benjamin Gilbert Original-Sender: "Debbugs-submit" Resent-CC: bug-coreutils@gnu.org Resent-Date: Tue, 05 Jul 2022 08:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 56392 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 56392@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.165700895618702 (code B ref -1); Tue, 05 Jul 2022 08:16:02 +0000 Received: (at submit) by debbugs.gnu.org; 5 Jul 2022 08:15:56 +0000 Received: from localhost ([127.0.0.1]:49266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o8dit-0004rT-IY for submit@debbugs.gnu.org; Tue, 05 Jul 2022 04:15:56 -0400 Received: from lists.gnu.org ([209.51.188.17]:47322) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o8dBo-0003uL-KI for submit@debbugs.gnu.org; Tue, 05 Jul 2022 03:41:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8dBo-0001CQ-CJ for bug-coreutils@gnu.org; Tue, 05 Jul 2022 03:41:44 -0400 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]:39676) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o8dBm-0004Fy-He for bug-coreutils@gnu.org; Tue, 05 Jul 2022 03:41:44 -0400 Received: by mail-qt1-x831.google.com with SMTP id h19so12579914qtp.6 for ; Tue, 05 Jul 2022 00:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=backtick-net.20210112.gappssmtp.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=ZhVZkK/634W3pfHHjiJ62AaUf+eiH4nsmAE2uikaS0Y=; b=tTSucjoRlTXa1e/pmNu0sxhYZgoXtwHL1TZF8mvNtugH+HmRYhQY5gGISPJeGj1CIU cJ0sCid6xGjPiYohrycCbs770lWvNOTOMQYwXni19kj26Nf7yr55UPEHKu2wZvIQmXgN rppfDGKxUjAlTSRAFacY6FNMWTIPvgCQjanV+eYSnOjXGFAG4XXcpqP8/aHAWkW7A+yr 61UYMa1ms3XOrii1PuY319OJMyi3yx/cUhCnpMs86uBq1nJT81tBAGUoK5tyzU0OcoyX CUrCPBhVeLEezq7CHaVSEwGS/o414kKcHtr+tHeEVYcunyiFkTfE1+qtcy0iKNzYWL8h 6w6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ZhVZkK/634W3pfHHjiJ62AaUf+eiH4nsmAE2uikaS0Y=; b=xHmMvrg6471MTIvhgNylvKXTa9q//cPjiXaNv7i1dvEA9rz18xdJqFCNYM8fUqCQYA MBXIcGGThWq07g4AuEdSf+4FCFjEI3Ay9x6b2wEPJwOnCl726zRZ7B06ihZsrOVHrsOT nWVHafnCbAIJ+QDPxnlaiYXG45HwMq/lEYxXDalkxvd403NJxbggrNswlglB+KrGndEm IAQFHiUgPW+wAzDLc5k1J1/lZK0J8lm+7CbZ+kshEorxshOnwcvMxxMbCyRwJWZ0ld6Z LieegzPEXYLAvrmfJJUcW/8+Vl6/2F4WrPZPWVQO0iLPsyVhE3bVGpciR/TBIAPpK5VH st3g== X-Gm-Message-State: AJIora9XDdxFRKqzoE4+t4YEiAiPpMqif+tg+MHGTYBMAXaEvDgUgjLQ +kPD29fdXm1thsI5GlDIomMTN+a0WrO+Oh7wq2A8oy+n9unDxvm4 X-Google-Smtp-Source: AGRyM1vKMj//LmZQ/7wFqzfmKTWFPNwX2b5xUrEWuZneLiP0pGfNFwWqMDyFQ0AV4ZzNtPccwsdTQgefO9NCgN68OE4= X-Received: by 2002:a05:622a:5d2:b0:31a:bf5:a6d3 with SMTP id d18-20020a05622a05d200b0031a0bf5a6d3mr27299486qtb.398.1657006900180; Tue, 05 Jul 2022 00:41:40 -0700 (PDT) MIME-Version: 1.0 From: Benjamin Gilbert Date: Tue, 5 Jul 2022 03:41:29 -0400 Message-ID: Content-Type: text/plain; charset="UTF-8" Received-SPF: none client-ip=2607:f8b0:4864:20::831; envelope-from=bgilbert@backtick.net; helo=mail-qt1-x831.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -2.3 (--) X-Mailman-Approved-At: Tue, 05 Jul 2022 04:15:49 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi, When `cp --reflink=always` fails because the filesystem does not support reflinks, I'd expect it not to leave anything at the destination path. However, it appears to leave an empty file instead: $ ls -l total 0 $ echo "some data" > src $ cp --reflink=always src dest cp: failed to clone 'dest' from 'src': Operation not supported $ ls -l total 4 -rw-rw-r--. 1 bgilbert bgilbert 0 Jul 5 01:27 dest -rw-rw-r--. 1 bgilbert bgilbert 10 Jul 5 01:27 src I'm seeing this on both coreutils 9.0 (Fedora 36) and 9.1.31-fa332 built from Git. Best, --Benjamin Gilbert From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 05 08:26:06 2022 Received: (at control) by debbugs.gnu.org; 5 Jul 2022 12:26:06 +0000 Received: from localhost ([127.0.0.1]:49594 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o8hcw-00018O-5a for submit@debbugs.gnu.org; Tue, 05 Jul 2022 08:26:06 -0400 Received: from mail-qk1-f169.google.com ([209.85.222.169]:39735) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o8dwT-0005Db-Nn for control@debbugs.gnu.org; Tue, 05 Jul 2022 04:30:00 -0400 Received: by mail-qk1-f169.google.com with SMTP id o26so1083254qkl.6 for ; Tue, 05 Jul 2022 01:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=backtick-net.20210112.gappssmtp.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=Rm/Sx17VubVIaDtugwa5+WxGrdFBzLzCi9G3ESu8+AE=; b=Z9pB8QL37/Oo31L0FbIanbtfyrC2baEiLUG0h2nWNV8b1O1qvSt0vLA57VTj7PVSSW eVyBwx/AMMONxt+VnenvFVrGRDaP0OtgPwauVTfRHsUklAkxp5o6a9YSZXcDWjZ3NkB6 Wm1YDWdcUfiS+qcvXifPb8Ul6XuyOj5kM+NfNHLYG9PmdcX9RHqZWuViMb6b9pXNJLbg c0xr6LRdG5Z7WCRv0r0oGhp9e1sxery4Cg2gq9K4yYQy5QhmkxKW6jJVObek9QaT8Mqx Hy36M8JwudoppFf9bKuUfE7IpTYfrcbJrf+gd67r3QmgvU4/V5DUPCI14yjHyNyHTFRI JVtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Rm/Sx17VubVIaDtugwa5+WxGrdFBzLzCi9G3ESu8+AE=; b=EkvsHMSKGOInifeZe3bUVwkP5e+XvLbmrjUz18ec9jcwY02NTrVDYZmJpnuNl6lh70 Q8Pn+KE6dSOmU64uVqXPz4bP4lcRnAvLJP9u+EiP6e2+X4ANe+EBaVzYv9/Qb3x5hO2M esWz1KtVn8DcnjcZa1I89Vw16vKjanep0gXU+XrBBAWF0JHdT5tCz3cvIe2QvjgELppr e4pd9c/k4NLyrv4ZjJRjIrlpfAMDLgfpjvIGa/s+lGCfcB0JFvQIOKealFjxRYdkTAuK ei/Bop+atbAdbUuJFFU9Ji7ctNDb0FOMkzt0YsKJRsLoQvaDsk1s/stsLzqEt/PhXNNC vMQg== X-Gm-Message-State: AJIora80j55eKjuBFnF/ErWSdnf+6PZlLJu/5wB1XZo1SVcQRBISVbpI svU+vWoXy09JNsJM197X+zejxjMFJEvKScjhFXTe/BAtzlUVDA== X-Google-Smtp-Source: AGRyM1uGPRtGz/1pgXbVyR6i2phkpeUl6xGnPKyj56lBMBS0yAt7uQBi5g6nDsYLylR45dWrXa9IAjv36tCPYebnJUo= X-Received: by 2002:a37:943:0:b0:6ae:db51:4ad4 with SMTP id 64-20020a370943000000b006aedb514ad4mr22424177qkj.16.1657009791860; Tue, 05 Jul 2022 01:29:51 -0700 (PDT) MIME-Version: 1.0 From: Benjamin Gilbert Date: Tue, 5 Jul 2022 04:29:41 -0400 Message-ID: Subject: To: control@debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: merge 56391 56392 thanks Whoops, double-posted. Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.222.169 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.222.169 listed in list.dnswl.org] 2.0 BLANK_SUBJECT Subject is present but empty -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Debbugs-Envelope-To: control X-Mailman-Approved-At: Tue, 05 Jul 2022 08:26:00 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) merge 56391 56392 thanks Whoops, double-posted. From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 07 11:39:57 2022 Received: (at control) by debbugs.gnu.org; 7 Jul 2022 15:39:57 +0000 Received: from localhost ([127.0.0.1]:57663 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o9Tbh-0006jg-4d for submit@debbugs.gnu.org; Thu, 07 Jul 2022 11:39:57 -0400 Received: from mail-wr1-f45.google.com ([209.85.221.45]:37597) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o9Tbc-0006jF-Kt; Thu, 07 Jul 2022 11:39:55 -0400 Received: by mail-wr1-f45.google.com with SMTP id n10so1581970wrc.4; Thu, 07 Jul 2022 08:39:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=7uSyzsVmPRatKjxWS6B/4M60JZUA6Uwyr74wsuq1yDI=; b=n0LgW6xj0m/PuMn6P/VM+gq4xcj402Igjx9k9R/NddHa5pQK5e6OmBt9xln8pXxCgS PyK/D0Oh9OqVQ/EByfjCjZyvOFFnp0iHKp0nBuOc33+HrdFwB0MyvBDL9+yBaXoqZ8J2 Ztrf7TPRpwmRUmvM8mZmMDJgSiy2Ovxzx06cNx4tjlx4ihfY+akVQGs9PhrTpeC7bG0L 8Ctl9lvjelHM6I02Xrrw/kBiMv5eUS8X4LyzCScQL9YV8Qh8IDI8OEUMXF9+oab1gYYR Pvy0FoXTIxkcOGjQrCZWgE2UXvBi2lZNyfAO2QH/rIIdcRSoyRt93HIOk7XxrkqtQD/n yGzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :subject:content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=7uSyzsVmPRatKjxWS6B/4M60JZUA6Uwyr74wsuq1yDI=; b=nKH8/xRGSs2R/ECJeDUayBHwTNsihbZi1/US2LkYlUjWrm9Js2rAitHoGaEufdBoVO CGHpJbk1OoLskK53u1uwJ3l5JgiFZSDouWm29TY1L+7ltFL3/NgN8+4kLRyNdLAoUeus 7nvNVeleZcsYa+uMiicWJW367auDLFsEuWEgJwZJoxnd1BiThrvQv5NvZJegmQ2TghlP mwVPCy2L7lgIL0ZHapv7aRy8xqJMmypNAJJE+l46XEicaODPdO7dcwYhmJBoEWI6xe8i 5VhSJ4tJd1LktyBw4q1NP35nDmfedoOn8uPmDnffHZESNBajmnvDeT+4F8MqMLuc0+Vc ggSw== X-Gm-Message-State: AJIora/cFBDTFhj3qj6tN6JpI8gTKsddh5WKs2AN5yMhVbKuQJhKW8Ru EWMl1p5E/WvvKbdyGPidrl8= X-Google-Smtp-Source: AGRyM1tIn9GQo3MRbbpOBrui9L3ztXRo0T7915Oj0xdgvmPGqW6ZvVR921a+L+RZuUItuEbbiUnatw== X-Received: by 2002:adf:f5c7:0:b0:21d:7f20:7508 with SMTP id k7-20020adff5c7000000b0021d7f207508mr8064308wrp.458.1657208386547; Thu, 07 Jul 2022 08:39:46 -0700 (PDT) Received: from [192.168.1.9] (95-44-90-175-dynamic.agg2.lod.rsl-rtd.eircom.net. [95.44.90.175]) by smtp.googlemail.com with ESMTPSA id q63-20020a1c4342000000b003973c54bd69sm26188898wma.1.2022.07.07.08.39.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Jul 2022 08:39:45 -0700 (PDT) Message-ID: Date: Thu, 7 Jul 2022 16:39:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:98.0) Gecko/20100101 Thunderbird/98.0 Subject: Re: bug#56391: `cp --reflink=always` creates empty file on failure Content-Language: en-US To: Paul Eggert References: <8edadd5f-a640-09ce-340f-71ea17e5ea02@cs.ucla.edu> <407528a6-0ee0-1404-0f6e-1b1b8dbcd779@draigBrady.com> <05ba0b87-b77f-a5a1-ac3f-872c02c53f9a@cs.ucla.edu> From: =?UTF-8?Q?P=c3=a1draig_Brady?= In-Reply-To: <05ba0b87-b77f-a5a1-ac3f-872c02c53f9a@cs.ucla.edu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: control Cc: bgilbert@backtick.net, Fridolin Pokorny , 56391@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.5 (/) forcemerge 56391 56392 close 56391 stop On 06/07/2022 20:48, Paul Eggert wrote: > On 7/6/22 06:17, Pádraig Brady wrote: >> This will usually work, but there are cases where this may lose data, >> as previously discussed at: >> >> https://bugzilla.redhat.com/show_bug.cgi?id=921708 >> http://lists.gnu.org/archive/html/coreutils/2013-03/msg00056.html >> >> I'm not sure cp can robustly clean up in this situation? > > Thanks for pointing me to those old discussions. As I understand it, the > worry is that FICLONE will only partly succeed, causing the destination > file to contain some (but not all) the input data, and then if we remove > the output file we'll lose the newly-made partial clone. I don't know > whether FICLONE can do that, but it sounds like a reasonable worry. > > If that understanding is correct, then the attached further patch should > suffice, so I boldly installed it. Yes that's better thanks. The code looks good, and should cater for any issues within a single cp instance. As for overlapping processes accessing a file, this may introduce new edge cases for where a file will be deleted. But I don't see a specific issue with that, given there are existing truncation races etc. with overlapping access to a file. I haven't thought through all scenarios TBH. marking this as done. thanks! Pádraig