Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3330638pxb; Fri, 12 Feb 2021 15:57:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJz79MXXypu8KPfVxKgWQ0vwZy7Uqr69pabHeAUMzbkCFmeCdD3iMOfpUSmglKWIbqBEsQdw X-Received: by 2002:a17:907:728b:: with SMTP id dt11mr5260711ejc.321.1613174241765; Fri, 12 Feb 2021 15:57:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613174241; cv=none; d=google.com; s=arc-20160816; b=GXVGvXRT9EeH8Gv6wOmGQihqneH/u8csyqudIvqt1LsSTVdjV/iuUGfUzIHCEU3XCj 09gVVXg+n45i+E5v+olPURZ2mb/LfWnytxEDclGWmQmHtfrptMHp98Ie0Cui5SMhJil9 Q222vvNSQb4jYFVle5U2D/FN8/tEqGjJTK8L1ZloH7uISohZboGaCA6Ae7UvhDNbUbrZ BjvSJzkcBjrQOMevSEfkSK5efwBOW3ozLAu+jSe3Rt7ipWmSSXWLl1hY0sulCYiM1WIE ORBPKHCJ6XRPYR9SNxiEtYy5AgzO+YmoFwKmjaG7vtngrsV5EeZ4lYrW1zaEp0mrjA6R myZg== 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:dkim-signature; bh=hcD3ItOSSzhksIukmDooqZH7t3U5vjH38a6i6CUdo/8=; b=iVtxbBO50m3uIEPb2cD/ghU/OJ19QeXta+bScokwxRfr3Ffn/Ukrzq6Fs9ZX1h0UIN +pc3Ry/WAkTfM6NePZrrbZX6nN6KGDjqPB1FJil0AkKwKoO8KDWkI3UYRLhD/XdFJae9 KBWiz9GOXJgNSel3CoVM35s5jtAB4L9QosC3jEUrT4PH7EyH8piPdxhQB6PP0PCjLPAN eoe2BjNe3uxmNsxcqOPPqZ81s0x38NKAB0W5BHw92ES6q6J63CnYjJ0vp4s6vqctdlwX /A1IhErw/g0ChrEbNoxD9ojsWuQoss78sdwja1Ccn3bASMnwOW5xY0kF/gku9/w6s4ZW Fq8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FNcUUbm3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c5si7370719edw.359.2021.02.12.15.56.58; Fri, 12 Feb 2021 15:57:21 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FNcUUbm3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230360AbhBLXzi (ORCPT + 99 others); Fri, 12 Feb 2021 18:55:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:52758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbhBLXza (ORCPT ); Fri, 12 Feb 2021 18:55:30 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4F4E864E25; Fri, 12 Feb 2021 23:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1613174089; bh=/OvqjRmaBoFigF88nuGOnn8jZUAKHCUoPALIy3wKaE4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FNcUUbm3NiiNAzM1st/UIKjwfMmXXIIrFHJRZwV4hTGBgdQIOvlQWHRfEwKpvZ2p+ RinxLoyCUKISZ2pU/lLkqmlRsyV+uFf7oJYeJKq2SpLDpoPtySvUXSz8QM+5PwIG1V JC0h1x2EUMc7NaFUG8dpVB3kpuyAJB1Y1Np9m4CXa8M4o2L9KIIrPRvpLCd10uIdga V3EefdYP9daNMHdpnbeGbsV/SwHhKO7PpKeJ/ex+NWQqdQl6IizE3DtPQ6xCbK4gMD FKk5b0p5E3Cj4AA6hWD8xdoSXZ0nlr+66cJVVP8TOCcoPOkfZvXJVqd4JvwWYrc5G7 3iKoBfhuQYung== Date: Fri, 12 Feb 2021 15:54:48 -0800 From: "Darrick J. Wong" To: Dave Chinner 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: <20210212235448.GH7187@magnolia> References: <20210212044405.4120619-1-drinkcat@chromium.org> <20210212124354.1.I7084a6235fbcc522b674a6b1db64e4aff8170485@changeid> <20210212230346.GU4626@dread.disaster.area> <20210212232726.GW4626@dread.disaster.area> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210212232726.GW4626@dread.disaster.area> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. :) 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... 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. 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). 3. #2, but fix the generic fallback to not suck so badly. That sounds like someone (else's) 2yr project. :P --D > Cheers, > > Dave. > -- > Dave Chinner > david@fromorbit.com