Received: by 10.192.165.148 with SMTP id m20csp2239268imm; Thu, 3 May 2018 12:50:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrhZF8EwHXLCE+emVzmzDb0mWU/5x2/OySS9yoFITCO2ZzGoeQOCHH/Z+0kHP9BWlQzOpMH X-Received: by 2002:a17:902:8e8b:: with SMTP id bg11-v6mr21919689plb.95.1525377009809; Thu, 03 May 2018 12:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525377009; cv=none; d=google.com; s=arc-20160816; b=FJFw9z7++VjnRgP2l0K/Id1Mhuk2mwX0QWHAFdEhGeZjfFypRHlth2C6avYc8d+vOT Z9koRQ786AN+3VakzWm61MmmdPfZJnixsojst3PtC0WwQSsDxz9JRTdgJXmU+8AU0IBe eSJbJelrxAXH3TaDT/IDLr7p++cjQpMTL55RKNphqjwBlxJGcbwuoTxz0Q+0RAh/eIX/ 1N1+MErrHgPywI/ArWTXAMoSD7CkiQIvRYjE/CnYhZy06GJ/C9sZOT2MdB6ykAZEyTJ6 hprV6KmNeZxrhLSrt17XY1alqEnQOdbHv4jUSVZGiCxE8EiTfeSFcZnUJfsFxhPOP8mX bBUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=Wy4UoBy3GQrLCw3+JlVx0W/Mt6Xr3FqqqBGfyfNM2qo=; b=Fv5J8Ecf9kYMQN73RFPKssSfPYSHlMexxyvFzZbnXRdqxmoQUN9uS7b3Vw3Zs3jlP/ 374miqC42BNV8QuL/D+qpTjKIVf/COZZ7N8cuTI72iGWPS8TfPNwFDFi07YH/Z8TJ0hD SShCoFHe2O3gmf4pP3WBy2bKCQjogGYGGtHROhkzJPnYa/7ktF07xkyv3DOGpM0krbYn ECqOjDTmXo7WG0F3bA+/RHFJND00RKV5KVpZuI//ogUvWEyvr/aX/R+Z/IBQ6DfmbnUM 45OKUHahJV70IiIrpLUEUJqdFlhthWU9QMApEGq+FNpOBy1tY+Ks15c3+beIDGSTltPQ sWBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OqTuMEJn; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c9-v6si13043156plz.501.2018.05.03.12.49.25; Thu, 03 May 2018 12:50:09 -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=@gmail.com header.s=20161025 header.b=OqTuMEJn; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751393AbeECTtB (ORCPT + 99 others); Thu, 3 May 2018 15:49:01 -0400 Received: from mail-yw0-f181.google.com ([209.85.161.181]:44491 "EHLO mail-yw0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751178AbeECTs7 (ORCPT ); Thu, 3 May 2018 15:48:59 -0400 Received: by mail-yw0-f181.google.com with SMTP id l142-v6so4815510ywc.11; Thu, 03 May 2018 12:48:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Wy4UoBy3GQrLCw3+JlVx0W/Mt6Xr3FqqqBGfyfNM2qo=; b=OqTuMEJnF31aYARwIIcxLwgGlLMjEs66SAw9gGk5NlzcgQSmRtq72SlFwXookzVGAM IjXJ8SV6aHyVA/21G9sBL+C5ncY+DsEU04wZHlM2BTJSpE6GPrgcWqNFpJ8Kw75SY+KY yuc99qX2u4sd/VeHxFxFTyAJ2n9UD3P3U7EocG4tlran+2U3T5uf3ZDR2AMNhQ4aSEme CkHloSmLmKu9YeKkTJ6MaoW0P78QKk7o4yo3bgD6ZopPudng0qasQfVdbJSvgufUMpNh jXdOq9dY1osKLHGT05eHVxaJNjuCwrgRQ/dKvzW21ftAp2IjsycbuZk62ROxUR0z2k1w 6YXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Wy4UoBy3GQrLCw3+JlVx0W/Mt6Xr3FqqqBGfyfNM2qo=; b=X5efMmvhtSq5Un+JgOYX29hA+tZr1N2nNNEIf2dQMLs2ANziOldGz8DplgdIe1IaDi 73cmW629ZNSFQyeHVfzUGuQJd0jEXRCxtEwuvI3UFZS1Gc7sLJG6e7bfPZyRQVRJ3t3V wzRzoix/80URO7xTm1SbpNSx5bjIwiVpb8a9mvYrwJRXBnS01F3zdN+roRUPufFw0pCz DeXqnmHXiNra1cZQMmWCaydovUOUKClNBvCqyAruilaVBxsmdzysnwElaFBlQsV2zOT1 hBwahek9hRAeNhXZhPITUtgKq+Oa4CQnUUYphK1R3Ww8Yi03fdjjRGTPHle3QIhj4PYb PisA== X-Gm-Message-State: ALQs6tC8VOClBQi8EgkAYxNm/tturyo7DMeDVsc6kFf8y00Q5BeHQPO+ zVFpc5nbuAvRVXp+lZlcv43VB/maegW560nODh1axA== X-Received: by 2002:a0d:e801:: with SMTP id r1-v6mr14399116ywe.294.1525376938856; Thu, 03 May 2018 12:48:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.13.239.198 with HTTP; Thu, 3 May 2018 12:48:58 -0700 (PDT) In-Reply-To: References: <20180412150826.20988-1-mszeredi@redhat.com> <20180412150826.20988-20-mszeredi@redhat.com> From: Amir Goldstein Date: Thu, 3 May 2018 22:48:58 +0300 Message-ID: Subject: Re: [RFC PATCH 19/35] ovl: readd reflink/copyfile/dedup support To: Miklos Szeredi Cc: overlayfs , linux-fsdevel , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 3, 2018 at 7:04 PM, Miklos Szeredi wrote: > On Tue, Apr 17, 2018 at 10:31 PM, Amir Goldstein wrote: >> On Thu, Apr 12, 2018 at 6:08 PM, Miklos Szeredi wrote: >>> Since set of arguments are so similar, handle in a common helper. >>> >>> Signed-off-by: Miklos Szeredi >>> --- >>> fs/overlayfs/file.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ >>> 1 file changed, 79 insertions(+) >>> >>> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c >>> index 9670e160967e..39b1b73334ad 100644 >>> --- a/fs/overlayfs/file.c >>> +++ b/fs/overlayfs/file.c >>> @@ -352,6 +352,81 @@ long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) >>> return ret; >>> } >>> >>> +enum ovl_copyop { >>> + OVL_COPY, >>> + OVL_CLONE, >>> + OVL_DEDUPE, >>> +}; >>> + >>> +static ssize_t 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; >>> + int ret; >>> + >>> + ret = ovl_real_file(file_out, &real_out); >>> + if (ret) >>> + return ret; >>> + >>> + ret = ovl_real_file(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); >> >> Problem: >> vfs_copy_file_range(ovl_lower_file, ovl_upper_file) on non samefs >> will get -EXDEV from ovl_copy_file_range(), so will not fall back >> to do_splice_direct(). > > This is not a regression, right? Right. > >> We may be better off checking in_sb != out_sb and returning >> -EOPNOTSUPP? not sure. > > I think we should fix vfs_copy_file_range() to fall back to copying if > not on the same fs. Not sure why it doesn't do that now. > There seems to be a posting to fix that as we speak... I seem to recall some flames from hch about a similar change that NFS folks where trying to push for. Let's see how this one goes. >> >> >>> + 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, len, >>> + real_out.file, pos_out); >> >> Problem: >> real_out can be a readonly fd (for is_admin), so we will be deduping >> the lower file. > > Ugh... > >> I guess this problem is mitigated in current code by may_write_real(). >> >> How can we deal with that sort of "write leak" without patching >> mnt_want_write_file()? > > We need to check before calling dedupe on real files that both are on upper. > > My problem is what error code to return. Neither EXDEV nor EINVAL > descibe the error adequately. It should be "We could dedupe if we > really wanted to, but it makes no sense to do so"... So now it > returns -EBADE, which means "data was different", but at least that > one should at least be expected by callers. > EPERM dest_fd is immutable Which exactly what may_write_real() returns today. Thanks, Amir.