Received: by 10.192.165.148 with SMTP id m20csp2021845imm; Thu, 3 May 2018 09:05:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrEpMT7PssO4W7hFEq6u15m0xn5/0A08Jxd/tkn9enxxanRI7pImFiiex0FyxO7S+RnuLyh X-Received: by 10.98.64.130 with SMTP id f2mr23613424pfd.83.1525363517105; Thu, 03 May 2018 09:05:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525363517; cv=none; d=google.com; s=arc-20160816; b=qhhQj3JZ8Uayz6rweE1w345NDGFZmhD+VLMyP8q7+LclGuoYLAF4NTaAZD/TrQ210H U5L0+GLs1KkqtFjsjPbpgi8Mobp8d3qdqimpTxAfb9py0BUS9oEmRhysQYxMW2bvY8/H 240FXF+Z8YKQ4JoRNBD3WidRxmRcihSAyqoXIXJv0B7JZtILh1dJYARquCk5xZpaUWBk 4ZcsWzBsudc9NXibghEj5deePg4VQ3bHeIzD8iNw3FTwVs8J1v5L7hRaruzCdlWvu9mQ W5PmBYJ3OjYSPtN5HlNFkhJGrh+KqhnHA8w2DT7tBYQ130Vg9rE9J331KUzvl0Wdj6R9 Fp8w== 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:arc-authentication-results; bh=hCHhWJyaxONIrD0VgQOW1Ud+FbtV+3UzA0LqHFyudM8=; b=fTtlt7gistVt7D6DRqkwm6GNSuyeqvxu5WxxXcHoS70v/q7nLAK+qmVGutdWshqh/e u2sgAe4QR2QL4M844hlDdXvrHz2YMA13krJZBelSqhvPEb0ebz4UOYansMFuhhT8r8+C XkB7gBhXzVyR3cFhY4cUNKGpT0sUN6on9HouGYBZDD5VKWZONwy3Nd+gGnFBrbFce8M5 tlbdpV1yyH7Wdp/Xeu4WdcOEVlnu0gpKXrFFQPppBX599OYKz8Xxe3g1oQLbTqVLqBF8 fBWGgdUciuseoKPlUdzDqiL5nRluzenPRD0Rkkg4Ey/SWumiXzSg8Wm6URFYZRSzTk/w y2Bw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d65si14515419pfa.263.2018.05.03.09.05.02; Thu, 03 May 2018 09:05:17 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751791AbeECQEi (ORCPT + 99 others); Thu, 3 May 2018 12:04:38 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:35491 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751621AbeECQEg (ORCPT ); Thu, 3 May 2018 12:04:36 -0400 Received: by mail-oi0-f65.google.com with SMTP id a6-v6so16558877oia.2 for ; Thu, 03 May 2018 09:04:36 -0700 (PDT) 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=hCHhWJyaxONIrD0VgQOW1Ud+FbtV+3UzA0LqHFyudM8=; b=VfMT0do6GHXY1eVBjs3gXkzXzJ7P5+LTKiRtgigQPIS1vzr/T5erV6c8zZD4wOkSik yawCREcUC5lfxdlo9MbBilaev7QD6jONeFKklI0X7vyzyC3ybQpryoxh53URqyHpYQVd FMJpK7S2r8JHmVLe2OIkqZfXNpZa0cKVQeNYFXj8jqcb9x1W48JdmtsgbkZyWh2QKqM7 PiAlFc4V79TTvR7quRYijIqvTOaIdElr2bDjj/l3sfeKJ9zflXU16x9I7x+uBSPbWhKa hXGmZ4uVexrdbV6Euj69WMlWLzyn7NdN26A5D3qS9jxs55NBC/JEF5/xW5yDboShTq3D A7Cw== X-Gm-Message-State: ALQs6tATBLkhSJZ8imCvKu+NkXlquYo3mbe395MPvTR+ihOr/pgkzxmh Gsq4ckeroIQatqiZda53n9cYAmQkax1LipA0eBmDiw== X-Received: by 2002:aca:f07:: with SMTP id 7-v6mr9484751oip.196.1525363475631; Thu, 03 May 2018 09:04:35 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:58cd:0:0:0:0:0 with HTTP; Thu, 3 May 2018 09:04:35 -0700 (PDT) In-Reply-To: References: <20180412150826.20988-1-mszeredi@redhat.com> <20180412150826.20988-20-mszeredi@redhat.com> From: Miklos Szeredi Date: Thu, 3 May 2018 18:04:35 +0200 Message-ID: Subject: Re: [RFC PATCH 19/35] ovl: readd reflink/copyfile/dedup support To: Amir Goldstein 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 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? > 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. > > >> + 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. Thanks, Miklos