Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp819090yba; Sat, 13 Apr 2019 14:49:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzL7tKOMBMuCQjayVbH+wKeKmMY5eBl5970NmPYDzOzzY5or5ZaFox7Z3XR/85N+VXl8bLS X-Received: by 2002:a17:902:2865:: with SMTP id e92mr44601588plb.269.1555192185905; Sat, 13 Apr 2019 14:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555192185; cv=none; d=google.com; s=arc-20160816; b=1AzFZagWAQQi6NCJmFlFRyVXZ85zogcYdOR19gGZdLWt2QEND3ZizqYqXFJFWBYo97 LJRUnNjuHi9LJOPA5US0nNLg0bIhpG/67nWZVbKDk8KYppBiKd74AWmZ2hK0XKdhXrVd O9I0K8B9Dcb6FDu4VF89VIf4wS+0Yqcf8jXoFi2+pGVdn3EOoaTQx9YIFQzb8UdvfTvK kG/tRKsl7tv1Lx6X+6QmX3uiWOH/80VlVqVVGcGR2A/QF4J273mb6h9ebWE4pTdYJlUi hpPKF/aeHRaMyq3p+uJK6sQ0KeVcxjbsb/7nRl3luz6lY04PHud3TEWofyrYf2e7wPlG 7YPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=zWHQFrxQ5ALEL7e28WuS09c9TVADIx4+Uu943gYarPE=; b=HKXlc+0+Mo6cJsJhLk4ec5Eq0xzIlETZ0xm5xfGMsDHx6uMgPMbiyBiS2YHkICnPwE 8cyM8QbBk6/fgAgoB5AxNRH36YEMQD1P/oE0FDJOOeW5deHc1y7J/o4xitPUbTlEuIOL wkxqy4GNHNSKrZbAAUhzcfxe201FVEuoKBx5s0oFZ4k4ZFfI3U5mIH1w1vR9dDOiogNk kl/Nuov+wbOOZ2n0wGLfi1SgUS2QoXL7UiU7KtqZvhvKwvY8GrrR/mSPzlYsrhSyB8rV wEYA7FtmiVfdCzyXcAkev0XqGvfYII7Iu88LL9yBLd6dwq+TozVKGOSF2/2kqG5hveBN h1Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=mcQrIs3M; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si23170253plr.136.2019.04.13.14.49.28; Sat, 13 Apr 2019 14:49:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=mcQrIs3M; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727105AbfDMVsp (ORCPT + 99 others); Sat, 13 Apr 2019 17:48:45 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:42593 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727052AbfDMVsp (ORCPT ); Sat, 13 Apr 2019 17:48:45 -0400 Received: by mail-pl1-f195.google.com with SMTP id cv12so6757669plb.9 for ; Sat, 13 Apr 2019 14:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=zWHQFrxQ5ALEL7e28WuS09c9TVADIx4+Uu943gYarPE=; b=mcQrIs3MsenKCn846ImL7z1F5wO+h8oXflpilDQP0Ra+4ev2WG/AGd4odQSRuGZJLP tw6wdX5l+MY5tAruHcaZ3UG8FabivNUyagOxF9XJ1XkNAv3SjeYZZEDp8fDZwGRdQkEx GzioCt82HcKH1JIOH19Ahd4LKLzafpvbv3tuFDafKre8JYCtasLnIodQ/Tydbh4wYPnu DNmITr+JmHp6DpeK355pds29xmtOx4f21AS2wmN8MWpnoRCgEPGj8YDvOWhLZq/J2+6n 9Qc6moLGsQaq6DDofnuRtP8t3JcMHlpEh25PSkC8eunbhqeDJnJUTIexM1+C7M73XYl3 umiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=zWHQFrxQ5ALEL7e28WuS09c9TVADIx4+Uu943gYarPE=; b=BQrJH/BNBjY+IKlLQlRKB86I0MMGKBiuL6ZyB4ry25u8Qkpkn8wQa71HX1n+dTguPb H1SIetO4CtXxR90GfWHPjD/+U2Ffbp24tIwLY4nP0+WdmUKq4By5bzishIk0t5ms3i6K 2skR5l5rG5KERzDYcOJ86aY5QX+SWxR0ulMJEu3CW7s7X8XuNOf0KAQromg70i1rk2Tl rmLMEevI1tA4IunMt2VW5IVcoD0AffxBLJsd3MhlQQ3E0a4KD+VP70vWQIZ5fPfk45Xs MI4Kq/BWWa7EvyPfhY2yv6gG1rICpWYKIAdyoeczFZ7VHNLIBaGXsNaJMKxu5II48SML vOXg== X-Gm-Message-State: APjAAAUebsCf3Yiz5mhnrtXcPyx0MXSyQ1nYshbsNMhlnq02Q2JAAg+c niCM3Q08eRyd672X/ew7yL1Gu8Zd+q8= X-Received: by 2002:a17:902:294b:: with SMTP id g69mr16951876plb.57.1555192124506; Sat, 13 Apr 2019 14:48:44 -0700 (PDT) Received: from ?IPv6:2600:1010:b02d:84af:491a:f204:96d6:e161? ([2600:1010:b02d:84af:491a:f204:96d6:e161]) by smtp.gmail.com with ESMTPSA id e13sm68110611pgb.37.2019.04.13.14.48.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Apr 2019 14:48:42 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] new flag COPY_FILE_RANGE_FILESIZE for copy_file_range() From: Andy Lutomirski X-Mailer: iPhone Mail (16E227) In-Reply-To: <20190413204947.9394-1-shawn@git.icu> Date: Sat, 13 Apr 2019 14:48:41 -0700 Cc: linux-api@vger.kernel, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <40254CBE-34B0-4783-8B19-FE7EA0BDA1E3@amacapital.net> References: <20190413204947.9394-1-shawn@git.icu> To: Shawn Landden Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Apr 13, 2019, at 1:49 PM, Shawn Landden wrote: >=20 > If flags includes COPY_FILE_RANGE_FILESIZE then the length > copied is the length of the file. off_in and off_out are > ignored. len must be 0 or the file size. >=20 > This implementation saves a call to stat() in the common case > of copying files. It does not fix any race conditions, but that > is possible in the future with this interface. >=20 > EAGAIN: If COPY_FILE_RANGE_FILESIZE was passed and len is not 0 > or the file size. I think you=E2=80=99re asking for trouble here. I assume you have some kind o= f race prevention in mind here. The trouble is that passing zero means copy= the whole thing, but the size-checking behavior is only available for nonze= ro sizes. This means that anyone who passes their idea of the size needs to a= ccount for inconsistent behavior if the size is zero. Also, what happens if the file size changes mid copy? I assume the result i= s more or less arbitrary, but you should document what behavior is allowed. = The docs should cover the case where you race against an O_APPEND write. >=20 > Signed-off-by: Shawn Landden > CC: > --- > fs/read_write.c | 14 +++++++++++++- > include/uapi/linux/stat.h | 4 ++++ > 2 files changed, 17 insertions(+), 1 deletion(-) >=20 > diff --git a/fs/read_write.c b/fs/read_write.c > index 61b43ad7608e..6d06361f0856 100644 > --- a/fs/read_write.c > +++ b/fs/read_write.c > @@ -1557,7 +1557,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, lo= ff_t pos_in, > struct inode *inode_out =3D file_inode(file_out); > ssize_t ret; >=20 > - if (flags !=3D 0) > + if ((flags & ~COPY_FILE_RANGE_FILESIZE) !=3D 0) > return -EINVAL; >=20 > if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode)) > @@ -1565,6 +1565,18 @@ ssize_t vfs_copy_file_range(struct file *file_in, l= off_t pos_in, > if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) > return -EINVAL; >=20 > + if (flags & COPY_FILE_RANGE_FILESIZE) { > + struct kstat stat; > + int error; > + error =3D vfs_getattr(&file_in->f_path, &stat, > + STATX_SIZE, 0); > + if (error < 0) > + return error; > + if (!(len =3D=3D 0 || len =3D=3D stat.size)) > + return -EAGAIN; > + len =3D stat.size; > + } > + > ret =3D rw_verify_area(READ, file_in, &pos_in, len); > if (unlikely(ret)) > return ret; > diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h > index 7b35e98d3c58..1075aa4666ef 100644 > --- a/include/uapi/linux/stat.h > +++ b/include/uapi/linux/stat.h > @@ -170,5 +170,9 @@ struct statx { >=20 > #define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger *= / >=20 > +/* > + * Flags for copy_file_range() > + */ > +#define COPY_FILE_RANGE_FILESIZE 0x00000001 /* Copy the full length of= the input file */ >=20 > #endif /* _UAPI_LINUX_STAT_H */ > --=20 > 2.20.1 >=20