Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4597379pxb; Sun, 14 Feb 2021 16:55:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzufDB/AjmytsOD5NGteGFLLfm/lbD0THROLDgj2n60XnXXMmK27d64fbGpdhkH/Ncdo4iU X-Received: by 2002:a17:906:a57:: with SMTP id x23mr13151416ejf.40.1613350505702; Sun, 14 Feb 2021 16:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613350505; cv=none; d=google.com; s=arc-20160816; b=u9yu1FHpIF1KGXK3UBxyM+JxSTgWXkUi5Xg4GvbdgI32g0vheq2rKnSWZ2BUnJQBVE OtEWDzskh2+iBH/j+dcdXazCfOr3EaQoeE4N7b2QFYvjgqP5GHF/ZzjeL1v3j9IGM2aj N3QU/quB3IM0flzAvk6mQdUug4o0h+JQ+xPatjklrV+TTF/Pte7Juwb4URt+WZubSsqQ OQp8CGLwAnoJshetX3EMqkvjDX+6e02B+9GpEQk/DAvdm2cy9jBB5eSgiK7ewoYlRQb8 rbT/4oiF+seAzrYeZbRLyYC9pBF+k50FPqFuNiUjaxOoCN87qVgNkDr7HnbGpmSq+2Wr NyDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=j4FQnFC3el6BJfHsHpp/vC7z9er+hdwJ6b9PiRLBF9Q=; b=s7XbWbBs6ZjCl8ZKRdY/uSWi0yR/Bp14VugYpUPoiazx+U5fGDNGROdB6Ob9KmumJA aylKYUUJChWNG1HqKmOVyRJOhUt3+XakrZxTnhy8Y3F4o2D3Zikp4V32Z9KTsqQ1bzkR KT1Hpyuqu7/2jKnMQA8IWF6DpRO6sqp1Ak6w2ktYe2sUqb6RyFAJgPvfUBv5BlGP7s5X R566Ah/CkuTd9+6B8+L2WEzhxKu29z1qZWN2tRpFhseUJvHuqwypTJqeJ36S3VlFXX0V O3/PotEI/GuFveJDTLAUwo0P1C/eH9smL7Wl4ccv1Z1TlxvD/VlZPoYINUVsQL5mn/KH PQYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f19si2031169eds.525.2021.02.14.16.54.40; Sun, 14 Feb 2021 16:55:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230107AbhBOAjm (ORCPT + 99 others); Sun, 14 Feb 2021 19:39:42 -0500 Received: from mail107.syd.optusnet.com.au ([211.29.132.53]:35842 "EHLO mail107.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbhBOAjl (ORCPT ); Sun, 14 Feb 2021 19:39:41 -0500 Received: from dread.disaster.area (pa49-181-52-82.pa.nsw.optusnet.com.au [49.181.52.82]) by mail107.syd.optusnet.com.au (Postfix) with ESMTPS id E6AA81140442; Mon, 15 Feb 2021 11:38:55 +1100 (AEDT) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1lBRuh-0053ei-3V; Mon, 15 Feb 2021 11:38:55 +1100 Date: Mon, 15 Feb 2021 11:38:55 +1100 From: Dave Chinner To: "Darrick J. Wong" Cc: Ian Lance Taylor , Greg KH , Nicolas Boichat , Alexander Viro , Luis Lozano , linux-fsdevel@vger.kernel.org, lkml Subject: Re: [PATCH 1/6] fs: Add flag to file_system_type to indicate content is generated Message-ID: <20210215003855.GY4626@dread.disaster.area> References: <20210212124354.1.I7084a6235fbcc522b674a6b1db64e4aff8170485@changeid> <20210212230346.GU4626@dread.disaster.area> <20210212232726.GW4626@dread.disaster.area> <20210212235448.GH7187@magnolia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210212235448.GH7187@magnolia> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=F8MpiZpN c=1 sm=1 tr=0 cx=a_idp_d a=7pwokN52O8ERr2y46pWGmQ==:117 a=7pwokN52O8ERr2y46pWGmQ==:17 a=kj9zAlcOel0A:10 a=qa6Q16uM49sA:10 a=7-415B0cAAAA:8 a=ag1SF4gXAAAA:8 a=Ctr0A7MYLLdSEb84NpgA:9 a=CjuIK1q_8ugA:10 a=biEYGPWJfzWAr4FL6Ov7:22 a=Yupwre4RP9_Eg_Bd0iYG:22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 12, 2021 at 03:54:48PM -0800, Darrick J. Wong wrote: > On Sat, Feb 13, 2021 at 10:27:26AM +1100, Dave Chinner wrote: > > On Fri, Feb 12, 2021 at 03:07:39PM -0800, Ian Lance Taylor wrote: > > > On Fri, Feb 12, 2021 at 3:03 PM Dave Chinner wrote: > > > > > > > > On Fri, Feb 12, 2021 at 04:45:41PM +0100, Greg KH wrote: > > > > > On Fri, Feb 12, 2021 at 07:33:57AM -0800, Ian Lance Taylor wrote: > > > > > > On Fri, Feb 12, 2021 at 12:38 AM Greg KH wrote: > > > > > > > > > > > > > > Why are people trying to use copy_file_range on simple /proc and /sys > > > > > > > files in the first place? They can not seek (well most can not), so > > > > > > > that feels like a "oh look, a new syscall, let's use it everywhere!" > > > > > > > problem that userspace should not do. > > > > > > > > > > > > This may have been covered elsewhere, but it's not that people are > > > > > > saying "let's use copy_file_range on files in /proc." It's that the > > > > > > Go language standard library provides an interface to operating system > > > > > > files. When Go code uses the standard library function io.Copy to > > > > > > copy the contents of one open file to another open file, then on Linux > > > > > > kernels 5.3 and greater the Go standard library will use the > > > > > > copy_file_range system call. That seems to be exactly what > > > > > > copy_file_range is intended for. Unfortunately it appears that when > > > > > > people writing Go code open a file in /proc and use io.Copy the > > > > > > contents to another open file, copy_file_range does nothing and > > > > > > reports success. There isn't anything on the copy_file_range man page > > > > > > explaining this limitation, and there isn't any documented way to know > > > > > > that the Go standard library should not use copy_file_range on certain > > > > > > files. > > > > > > > > > > But, is this a bug in the kernel in that the syscall being made is not > > > > > working properly, or a bug in that Go decided to do this for all types > > > > > of files not knowing that some types of files can not handle this? > > > > > > > > > > If the kernel has always worked this way, I would say that Go is doing > > > > > the wrong thing here. If the kernel used to work properly, and then > > > > > changed, then it's a regression on the kernel side. > > > > > > > > > > So which is it? > > > > > > > > Both Al Viro and myself have said "copy file range is not a generic > > > > method for copying data between two file descriptors". It is a > > > > targetted solution for *regular files only* on filesystems that store > > > > persistent data and can accelerate the data copy in some way (e.g. > > > > clone, server side offload, hardware offlead, etc). It is not > > > > intended as a copy mechanism for copying data from one random file > > > > descriptor to another. > > > > > > > > The use of it as a general file copy mechanism in the Go system > > > > library is incorrect and wrong. It is a userspace bug. Userspace > > > > has done the wrong thing, userspace needs to be fixed. > > > > > > OK, we'll take it out. > > > > > > I'll just make one last plea that I think that copy_file_range could > > > be much more useful if there were some way that a program could know > > > whether it would work or not. > > Well... we could always implement a CFR_DRYRUN flag that would run > through all the parameter validation and return 0 just before actually > starting any real copying logic. But that wouldn't itself solve the > problem that there are very old virtual filesystems in Linux that have > zero-length regular files that behave like a pipe. > > > If you can't tell from userspace that a file has data in it other > > than by calling read() on it, then you can't use cfr on it. > > I don't know how to do that, Dave. :) If stat returns a non-zero size, then userspace knows it has at least that much data in it, whether it be zeros or previously written data. cfr will copy that data. The special zero length regular pipe files fail this simple "how much data is there to copy in this file" check... > Frankly I'm with the Go developers on this -- one should detect c_f_r by > calling it and if it errors out then fall back to the usual userspace > buffer copy strategy. > > That still means we need to fix the kernel WRT these weird old > filesystems. One of... And that is the whole problem here, not that cfr is failing. cfr is behaving correctly and consistently as the filesystem is telling the kernel there is no data in the file (i.e. size = 0). > 1. Get rid of the generic fallback completely, since splice only copies > 64k at a time and ... yay? I guess it at least passes generic/521 and > generic/522 these days. I've had a few people ask me for cfr to not fall back to a manual copy because they only want it to do something if it can accelerate the copy to be faster than userspace can copy the data itself. If the filesystem can't optimise the copy in some way, they want to know so they can do something else of their own chosing. Hence this seems like the sane option to take here... > 2. Keep it, but change c_f_r to require that both files have a > ->copy_file_range implementation. If they're the same then we'll call > the function pointer, if not, we call the generic fallback. This at > least gets us back to the usual behavior which is that filesystems have > to opt in to new functionality (== we assume they QA'd all the wunnerful > combinations). That doesn't address the "write failure turns into short read" problem with the splice path... > 3. #2, but fix the generic fallback to not suck so badly. That sounds > like someone (else's) 2yr project. :P Not mine, either. Cheers, Dave. -- Dave Chinner david@fromorbit.com