Received: by 10.192.165.148 with SMTP id m20csp4383785imm; Tue, 8 May 2018 07:39:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZphRgX3/SpiCH3taYHCUtEmd7+fgG/78tx0iVndzn3ZWv9ZxbQQpxsL18wmYV5pavZHyBHL X-Received: by 2002:a17:902:7795:: with SMTP id o21-v6mr21480782pll.36.1525790351182; Tue, 08 May 2018 07:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525790351; cv=none; d=google.com; s=arc-20160816; b=t+XNFXiWLXCZCMeapkkfs0tqgV1Z7bLA84rLYIVZbpm+4iLgUmOmETkFMTi4Ty+sL4 Lj4uvuoPigM9D7dZTfnY9OZPRvSak2Dmy35LmlkLugwsjZEXOpBgLwc+L+/uk/rlsRUZ VodXVULLe62LFb4PZdDNF1ersZBxLtwL9ogQqRQ/XACiIByDlO2EeFcOYLFM82lTQbhR tgCDFHKw4DSPN/TP2ELrc51p+8+F2FSQJM2ssG6mBHaig49+Bi+mMeYa3Qc15rxQonl8 grxCgHjUchflxeWVdKzSKciq11/eV1QPdllTrpNmNitl78Vabye0n/VFBY5Clu2mbhZ+ vV8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Cpm1gQ8nFLMT3pZQfouUmOQvBjvBMZ3W0M++XZmsrT8=; b=iEqykjlYruRfbgo/T+sknb4MQ0KQbcLa2xFGO/qAy4IGx/T7Wnd3NhIqRduzyg6cW/ SwuHkeBeWG5jkGFwXHxrlHRvJypfqI1BmdUZKAAIz9cCvf/N25f/YUoAXW5wFS7PlzI7 jenzjC0Vl+p50Gjs+JaAUbkC0/1U0MO3PldchHxxSHpBrZKeAQcvfSrwlB5qIGqkHVSn Gf6+hz8xpPCXB11wJZxWJt5kK7Bt5rC3M0Zrg+GLMU61zwdYoTrlTgUtymNOiIE61nbk f5wCnzxSvR46gZiTfZ5zI1uA9mbKCDKxAibEozOSfta/o2hgr7Y0OxWodiMb18fMaqxS 1u5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=LazIjHLw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o186-v6si19839915pga.350.2018.05.08.07.38.56; Tue, 08 May 2018 07:39:11 -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=@oracle.com header.s=corp-2017-10-26 header.b=LazIjHLw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932634AbeEHOiZ (ORCPT + 99 others); Tue, 8 May 2018 10:38:25 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:54984 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932375AbeEHOiX (ORCPT ); Tue, 8 May 2018 10:38:23 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w48EQJM4123230; Tue, 8 May 2018 14:38:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=Cpm1gQ8nFLMT3pZQfouUmOQvBjvBMZ3W0M++XZmsrT8=; b=LazIjHLwhveNq34iHDfOEyhxrVjEbPQL+sUWxJJ4BYPpbdDxJA3UjrKJG+iE7Yk0HTmO KoWTkncFXs3Lg8TkWy4Ebz5adUfGD76bE0I0oK9X2z3VQEghALKY/jikWWunuzsqJfyp dHR3Pck5uWF4DRpZDs0JUfzWhUfgG8wI+86Awt3XS0Qs0coxRY/VVvUi9rvFTi/jb/mq OQU+SY6Om+eYr79cvn03XEQq6zlq36cjM4wX+/+y84+TbvhxqixSEaYzC+qXsgi8OqGW FDsoqkd94D3bb0TgKVPTdZ1HqmcX1obP6NHlpY9BNWICvk3DngtC6XI5V+NP/HhpjnsE 2A== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2hs5938w2w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 08 May 2018 14:38:04 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w48Ec3U8003919 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 May 2018 14:38:03 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w48Ec3Zj005187; Tue, 8 May 2018 14:38:03 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 08 May 2018 07:38:03 -0700 Date: Tue, 8 May 2018 07:38:02 -0700 From: "Darrick J. Wong" To: Miklos Szeredi Cc: Miklos Szeredi , overlayfs , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 21/35] ovl: add reflink/copyfile/dedup support Message-ID: <20180508143802.GC9510@magnolia> References: <20180507083807.28792-1-mszeredi@redhat.com> <20180507083807.28792-22-mszeredi@redhat.com> <20180507204350.GB9510@magnolia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8886 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805080140 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 08, 2018 at 04:13:01PM +0200, Miklos Szeredi wrote: > On Mon, May 7, 2018 at 10:43 PM, Darrick J. Wong > wrote: > > On Mon, May 07, 2018 at 10:37:53AM +0200, Miklos Szeredi wrote: > >> Since set of arguments are so similar, handle in a common helper. > >> > >> Signed-off-by: Miklos Szeredi > >> --- > >> fs/overlayfs/file.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ > >> 1 file changed, 88 insertions(+) > >> > >> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c > >> index ce871a15e185..2ac95c95e8e6 100644 > >> --- a/fs/overlayfs/file.c > >> +++ b/fs/overlayfs/file.c > >> @@ -382,6 +382,90 @@ static long ovl_compat_ioctl(struct file *file, unsigned int cmd, > >> return ovl_ioctl(file, cmd, arg); > >> } > >> > >> +enum ovl_copyop { > >> + OVL_COPY, > >> + OVL_CLONE, > >> + OVL_DEDUPE, > >> +}; > >> + > >> +static s64 ovl_copyfile(struct file *file_in, loff_t pos_in, > >> + struct file *file_out, loff_t pos_out, > >> + u64 len, unsigned int flags, enum ovl_copyop op) > >> +{ > >> + struct inode *inode_out = file_inode(file_out); > >> + struct fd real_in, real_out; > >> + const struct cred *old_cred; > >> + s64 ret; > >> + > >> + ret = ovl_real_fdget(file_out, &real_out); > >> + if (ret) > >> + return ret; > >> + > >> + ret = ovl_real_fdget(file_in, &real_in); > >> + if (ret) { > >> + fdput(real_out); > >> + return ret; > >> + } > >> + > >> + old_cred = ovl_override_creds(file_inode(file_out)->i_sb); > >> + switch (op) { > >> + case OVL_COPY: > >> + ret = vfs_copy_file_range(real_in.file, pos_in, > >> + real_out.file, pos_out, len, flags); > >> + break; > >> + > >> + case OVL_CLONE: > >> + ret = vfs_clone_file_range(real_in.file, pos_in, > >> + real_out.file, pos_out, len); > >> + break; > >> + > >> + case OVL_DEDUPE: > >> + ret = vfs_dedupe_file_range_one(real_in.file, pos_in, > >> + real_out.file, pos_out, len); > >> + break; > >> + } > >> + revert_creds(old_cred); > >> + > >> + /* Update size */ > >> + ovl_copyattr(ovl_inode_real(inode_out), inode_out); > >> + > >> + fdput(real_in); > >> + fdput(real_out); > >> + > >> + return ret; > >> +} > >> + > >> +static ssize_t ovl_copy_file_range(struct file *file_in, loff_t pos_in, > >> + struct file *file_out, loff_t pos_out, > >> + size_t len, unsigned int flags) > >> +{ > >> + return ovl_copyfile(file_in, pos_in, file_out, pos_out, len, flags, > >> + OVL_COPY); > >> +} > >> + > >> +static int ovl_clone_file_range(struct file *file_in, loff_t pos_in, > >> + struct file *file_out, loff_t pos_out, u64 len) > >> +{ > >> + return ovl_copyfile(file_in, pos_in, file_out, pos_out, len, 0, > >> + OVL_CLONE); > >> +} > >> + > >> +static s64 ovl_dedupe_file_range(struct file *file_in, loff_t pos_in, > >> + struct file *file_out, loff_t pos_out, > >> + u64 len) > >> +{ > >> + /* > >> + * Don't copy up because of a dedupe request, this wouldn't make sense > >> + * most of the time (data would be duplicated instead of deduplicated). > >> + */ > >> + if (!ovl_inode_upper(file_inode(file_in)) || > >> + !ovl_inode_upper(file_inode(file_out))) > >> + return -EPERM; > > > > /me wonders, why not EOPNOTSUPP? That's what we've been using (in xfs > > anyway) for "filesystem doesn't want to let you do this". > > EOPNOTSUPP might be interpreted as "this filesystem doesn't support > dedupe", even though here it's just "these two particular files don't > support dedupe". ocfs2 already uses EOPNOTSUPP for 'these two particular files don't support dedupe/reflink'. Granted, the manpage would seem to leave open the possibility of using EOPNOTSUPP or EINVAL for the "can't do it to these two files" case. --D > > > > (Or I guess EXDEV, but "cross-device link not supported" might not be > > quite what you want users to see...) > > Hmm, I like EPERM better. EPERM means something like "you can't do > this for some unspecified reason". This is exactly the case here. > > Thanks, > Miklos