Received: by 10.192.165.148 with SMTP id m20csp4356250imm; Tue, 8 May 2018 07:13:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpnHCBqalKBunOSsRuBh1WFu5idrDIynYcyauR4nN5m4zYw4UhxH9LY7u+dXLF2viNt+/gR X-Received: by 10.98.74.136 with SMTP id c8mr40313440pfj.23.1525788808948; Tue, 08 May 2018 07:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525788808; cv=none; d=google.com; s=arc-20160816; b=UQcWPpf6+3jh+Nacl8q6CXnKmkel9WKmqSjn2jQht1vT4yEM/MCM5GnkKcq7sp8cPt HO+T8m5Pa+cNNn8cfGuvCfrXS4xqiUnB+nHQQosek4BLqD5cDVFvhjIrGxfLdy/Nueyx S3LnzYeUe8q3jYt3pqqkGmQwMJe77d89eD/L6dHI8oO+ndKsShfi2oKVq+5eH1wDyiIM gZ8r+XlTXSlJY9TWNKSRFEwg99z2gey3Pa+aSWbFeYTfjdEvrhbw1zgoUjAuG7qfpmkm iMULXy/PNKWHostw6ySWmqI3GSi+yLs5oymtQ1fmhlPqZCaOOtBrQ8VmRX1y3IhLFDHJ mKWA== 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=yVtzpNOER1woFvJueziiHQGcr03Bh3eOUi7fm4zxclE=; b=TMeVT8VZyWM/R0D0b3ApUNkRxivONN64hYYmrdoet2mbN3v+QQf3g8ows0J1Hubu4V NXRi2MUY2Ed6ujag80EpZW5YG+LpnqSfxyCx9pr+2uwJrGt7AQvTqF25vtImjZS5i5+G 3urp7DLSNe0h6FfY0JH4b5c1n2Qw8i9ImtaF5kWzxMloDNjIb81mFCci1TDM5xwF2a2B adrrxiI5Koo1bM08xPdUlPpwv43Hw5PseFA8LtH+qQKDWC9RXIxb9ugLblFmQ9ZKuCm3 UkXElSyW497bSr9mpA+LDR6n2bcyzKMOBkneG8krHJlkbKJgi2rVUf9KShd3z3sPq3uU pHAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=kBGYb4PQ; 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 a71-v6si19717361pge.159.2018.05.08.07.13.14; Tue, 08 May 2018 07:13:28 -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=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=kBGYb4PQ; 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 S1755349AbeEHONE (ORCPT + 99 others); Tue, 8 May 2018 10:13:04 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:34886 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755133AbeEHONC (ORCPT ); Tue, 8 May 2018 10:13:02 -0400 Received: by mail-oi0-f67.google.com with SMTP id a6-v6so28450987oia.2 for ; Tue, 08 May 2018 07:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=yVtzpNOER1woFvJueziiHQGcr03Bh3eOUi7fm4zxclE=; b=kBGYb4PQE29tJGpRK0PeKAZ1jsk+X7E8EUFG53RdgveIOs32tC9h11xKDIlgUcksWf otuKBWlVRuF/bw9B6pl4lSG7Zz6lGC2iSzYusaODf6NJSA6hohSAiEnHCSHbZ2l4xxQ7 94avFOZYsTYK1lTERLJlmQzQFwl7oltpgjV2s= 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=yVtzpNOER1woFvJueziiHQGcr03Bh3eOUi7fm4zxclE=; b=olyJAvKEv/iDu1ILkHHcFb7XHfD28OObSuf6KwI3KeCvBuuGSAbawdaEcgWmC0w6GU Cq3ai7xIEcJBblO126VwNzYHWyaeQwtzWg/1DYInK1Z16N5RJG/n5r4dvlw8ffgEi/LZ 2kRb0YfydEJzMiJq4cHjCwBuxWelE+OF0Lza50iFDvBGas9Zj/2UMu1zOevlt/RjT6IJ t0O2D1l9f4ijyb8aNN1kZ0/STmjzyYzM67bP7vVWjgCGtnzxq9cxGju9hzltAWnyU4UO 5LiUqK+PkmZsmr6Jz0vhOTGwGK1N/dbPnrCm/vdOvPEGu2ILAqv83of+NqJTOaX9Q32j jlrA== X-Gm-Message-State: ALQs6tBNgZPCf1umTWISY1xukUwgztDEGMV0skK68A3pNLjy5fFGHOwG FPPCaJKInXAYoO1YOKRbARfgEYuSqKNdx9c/gKfg5w== X-Received: by 2002:a54:4e8b:: with SMTP id c11-v6mr12692586oiy.250.1525788781854; Tue, 08 May 2018 07:13:01 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:5303:0:0:0:0:0 with HTTP; Tue, 8 May 2018 07:13:01 -0700 (PDT) X-Originating-IP: [176.63.54.97] In-Reply-To: <20180507204350.GB9510@magnolia> References: <20180507083807.28792-1-mszeredi@redhat.com> <20180507083807.28792-22-mszeredi@redhat.com> <20180507204350.GB9510@magnolia> From: Miklos Szeredi Date: Tue, 8 May 2018 16:13:01 +0200 Message-ID: Subject: Re: [PATCH v2 21/35] ovl: add reflink/copyfile/dedup support To: "Darrick J. Wong" Cc: Miklos Szeredi , overlayfs , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org 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 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". > > (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