Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp789615yba; Sat, 13 Apr 2019 13:51:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqykaQuTmsEa7rdAZKqQpSqC6+wsY6EmliCjTQZYUFFu+yczcHcaQPWHMAnyTEvGIb3/SWNu X-Received: by 2002:a63:5a47:: with SMTP id k7mr61347168pgm.174.1555188662076; Sat, 13 Apr 2019 13:51:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555188662; cv=none; d=google.com; s=arc-20160816; b=irtdi83trAcJWfgaPz+inmq+myNxMI8sVh09CX2mHchA6v5FzoKxOs1gLkGQ2LayR0 SxLFEkf+fb89AO64O/E8KZbnLNrAn+wBnxRIxtkZgA5zcsNRcUdFKfGcuz8eBkvqoy6g xEvuzbB17MqNuaxeZT33nrvMtRC+KJ+m2p+AoAp3Jgmeh9xSADLd+3yDfFpHwhSwYedB lgGVKuDe5FXvEO4y5CIPw+gB3DygtreP7Bou7GOuRlkhLI21dvg4BYlXIWrk2Tu/pfS+ lZ7zKmq7LmRM5NuvVMdsYIDqmal/nQC8gNEnsK6/vVLaZM9k8exkRtSc4JQ9PryMToZv gpJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from; bh=ognk4lz2NDKt1DvD/X12198HfbOIyneoWr847fqKsa4=; b=vjZM+fTCyTGQ0njUFdGjcNkAAuCa1FM19Tpy0U11LwRysRcrRkGIoAA43tMde7O3GE m+5zs+QCRvRS+AoF8lq6Prh+zMny5VjZSUSxC1XBvASShxr635BtQqTm9k9sGpukMQul CCBrMyWbCRAOq02SgVh/UDsQic/dEPRCP2lA9695iFXBVLrOP020dysVtKZrynN8+UuP zQMTsgz6qAUs5TgbGiDIKrprIgozEQPouLB+kaTjOVzgcjrQNd8DbR+4rGxp+aBRlBB5 2Iqty5VlF5L/yrHcpigBhJ4atHikNYWSld7xP826qiV1CXZIHN7Jir6M0WpmsWFYeLn+ hZAg== ARC-Authentication-Results: i=1; mx.google.com; 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 ay11si41627742plb.360.2019.04.13.13.50.46; Sat, 13 Apr 2019 13:51:02 -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; 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 S1727223AbfDMUuF (ORCPT + 99 others); Sat, 13 Apr 2019 16:50:05 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:37502 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726936AbfDMUuE (ORCPT ); Sat, 13 Apr 2019 16:50:04 -0400 Received: by mail-vs1-f67.google.com with SMTP id w13so7472201vsc.4; Sat, 13 Apr 2019 13:50:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ognk4lz2NDKt1DvD/X12198HfbOIyneoWr847fqKsa4=; b=tc+SgH3ATadYvtrtwOke3t9Weqt9+S5mLibnW/5yMTw7OZ8BPiZOLezVasDIlqzC6K UhD1+88Mk5sEyrYag/nbOc1jJgL1TEcOMxgHQckPsn67dfJGsL0WYcPXpRkLupXmrCJg +6TxAI9LLuBVijxd0m1Ta9RXjtLxiUWIVjNf1x1UC1lm2p4uOQ/MVKwiya+ADuMAhuWN D+EAZ/zVFCfxeb5rpdE3egicvshcPjvwTOLOfYH/HUNenhLiynqKr3CVvLV+HWmBP1MB Yo74Ox4fBs37uRQoAC7xWjVhj+6IaG3Rnuchd2Hit47sDrKPlWcY1gmjbVEK0iZ3dSu3 DrSw== X-Gm-Message-State: APjAAAXyfwzt1BIIIYydB3Th3nQ4kOXOZ8klhkdaKWHOgsB5DzKmL1NZ DkevxzY01Gaa7/GLef9d3qw= X-Received: by 2002:a67:c498:: with SMTP id d24mr16090328vsk.182.1555188602527; Sat, 13 Apr 2019 13:50:02 -0700 (PDT) Received: from localhost.localdomain ([201.240.145.139]) by smtp.gmail.com with ESMTPSA id b197sm54074242vkd.9.2019.04.13.13.50.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Apr 2019 13:50:01 -0700 (PDT) From: Shawn Landden Cc: linux-api@vger.kernel, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Landden , linux-api@vger.kernel.org Subject: [PATCH] new flag COPY_FILE_RANGE_FILESIZE for copy_file_range() Date: Sat, 13 Apr 2019 15:49:47 -0500 Message-Id: <20190413204947.9394-1-shawn@git.icu> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. EAGAIN: If COPY_FILE_RANGE_FILESIZE was passed and len is not 0 or the file size. Signed-off-by: Shawn Landden CC: --- fs/read_write.c | 14 +++++++++++++- include/uapi/linux/stat.h | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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, loff_t pos_in, struct inode *inode_out = file_inode(file_out); ssize_t ret; - if (flags != 0) + if ((flags & ~COPY_FILE_RANGE_FILESIZE) != 0) return -EINVAL; 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, loff_t pos_in, if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) return -EINVAL; + if (flags & COPY_FILE_RANGE_FILESIZE) { + struct kstat stat; + int error; + error = vfs_getattr(&file_in->f_path, &stat, + STATX_SIZE, 0); + if (error < 0) + return error; + if (!(len == 0 || len == stat.size)) + return -EAGAIN; + len = stat.size; + } + ret = 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 { #define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */ +/* + * Flags for copy_file_range() + */ +#define COPY_FILE_RANGE_FILESIZE 0x00000001 /* Copy the full length of the input file */ #endif /* _UAPI_LINUX_STAT_H */ -- 2.20.1